/* A Bison parser, made by GNU Bison 2.3.  */

/* Skeleton implementation for Bison's Yacc-like parsers in C

   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
   Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.  */

/* As a special exception, you may create a larger work that contains
   part or all of the Bison parser skeleton and distribute that work
   under terms of your choice, so long as that work isn't itself a
   parser generator using the skeleton or a modified version thereof
   as a parser skeleton.  Alternatively, if you modify or redistribute
   the parser skeleton itself, you may (at your option) remove this
   special exception, which will cause the skeleton and the resulting
   Bison output files to be licensed under the GNU General Public
   License without this special exception.

   This special exception was added by the Free Software Foundation in
   version 2.2 of Bison.  */

/* C LALR(1) parser skeleton written by Richard Stallman, by
   simplifying the original so-called "semantic" parser.  */

/* All symbols defined below should begin with yy or YY, to avoid
   infringing on user name space.  This should be done even for local
   variables, as they might otherwise be expanded by user macros.
   There are some unavoidable exceptions within include files to
   define necessary library symbols; they are noted "INFRINGES ON
   USER NAME SPACE" below.  */

/* Identify Bison output.  */
#define YYBISON 1

/* Bison version.  */
#define YYBISON_VERSION "2.3"

/* Skeleton name.  */
#define YYSKELETON_NAME "yacc.c"

/* Pure parsers.  */
#define YYPURE 1

/* Using locations.  */
#define YYLSP_NEEDED 0

/* Substitute the variable and function names.  */
#define yyparse tengSyntax_parse
#define yylex   tengSyntax_lex
#define yyerror tengSyntax_error
#define yylval  tengSyntax_lval
#define yychar  tengSyntax_char
#define yydebug tengSyntax_debug
#define yynerrs tengSyntax_nerrs


/* Tokens.  */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
   /* Put the tokens into the symbol table, so that GDB and other debuggers
      know about them.  */
   enum yytokentype {
     LEX_TEXT = 258,
     LEX_DEBUG = 259,
     LEX_BYTECODE = 260,
     LEX_INCLUDE = 261,
     LEX_FORMAT = 262,
     LEX_ENDFORMAT = 263,
     LEX_FRAGMENT = 264,
     LEX_ENDFRAGMENT = 265,
     LEX_IF = 266,
     LEX_ELSEIF = 267,
     LEX_ELSE = 268,
     LEX_ENDIF = 269,
     LEX_SET = 270,
     LEX_EXPR = 271,
     LEX_TENG = 272,
     LEX_END = 273,
     LEX_SHORT_EXPR = 274,
     LEX_SHORT_DICT = 275,
     LEX_SHORT_END = 276,
     LEX_CTYPE = 277,
     LEX_ENDCTYPE = 278,
     LEX_REPEATFRAG = 279,
     LEX_ASSIGN = 280,
     LEX_COMMA = 281,
     LEX_COLON = 282,
     LEX_COND_EXPR = 283,
     LEX_OR = 284,
     LEX_AND = 285,
     LEX_BITOR = 286,
     LEX_BITXOR = 287,
     LEX_BITAND = 288,
     LEX_STR_NE = 289,
     LEX_STR_EQ = 290,
     LEX_NE = 291,
     LEX_EQ = 292,
     LEX_LT = 293,
     LEX_GT = 294,
     LEX_LE = 295,
     LEX_GE = 296,
     LEX_CONCAT = 297,
     LEX_SUB = 298,
     LEX_ADD = 299,
     LEX_REPEAT = 300,
     LEX_MOD = 301,
     LEX_DIV = 302,
     LEX_MUL = 303,
     LEX_UNARY = 304,
     LEX_BITNOT = 305,
     LEX_NOT = 306,
     LEX_CASE = 307,
     LEX_DEFINED = 308,
     LEX_EXIST = 309,
     LEX_L_PAREN = 310,
     LEX_R_PAREN = 311,
     LEX_DICT_INDIRECT = 312,
     LEX_DICT = 313,
     LEX_VAR = 314,
     LEX_SELECTOR = 315,
     LEX_IDENT = 316,
     LEX_STRING = 317,
     LEX_INT = 318,
     LEX_REAL = 319
   };
#endif
/* Tokens.  */
#define LEX_TEXT 258
#define LEX_DEBUG 259
#define LEX_BYTECODE 260
#define LEX_INCLUDE 261
#define LEX_FORMAT 262
#define LEX_ENDFORMAT 263
#define LEX_FRAGMENT 264
#define LEX_ENDFRAGMENT 265
#define LEX_IF 266
#define LEX_ELSEIF 267
#define LEX_ELSE 268
#define LEX_ENDIF 269
#define LEX_SET 270
#define LEX_EXPR 271
#define LEX_TENG 272
#define LEX_END 273
#define LEX_SHORT_EXPR 274
#define LEX_SHORT_DICT 275
#define LEX_SHORT_END 276
#define LEX_CTYPE 277
#define LEX_ENDCTYPE 278
#define LEX_REPEATFRAG 279
#define LEX_ASSIGN 280
#define LEX_COMMA 281
#define LEX_COLON 282
#define LEX_COND_EXPR 283
#define LEX_OR 284
#define LEX_AND 285
#define LEX_BITOR 286
#define LEX_BITXOR 287
#define LEX_BITAND 288
#define LEX_STR_NE 289
#define LEX_STR_EQ 290
#define LEX_NE 291
#define LEX_EQ 292
#define LEX_LT 293
#define LEX_GT 294
#define LEX_LE 295
#define LEX_GE 296
#define LEX_CONCAT 297
#define LEX_SUB 298
#define LEX_ADD 299
#define LEX_REPEAT 300
#define LEX_MOD 301
#define LEX_DIV 302
#define LEX_MUL 303
#define LEX_UNARY 304
#define LEX_BITNOT 305
#define LEX_NOT 306
#define LEX_CASE 307
#define LEX_DEFINED 308
#define LEX_EXIST 309
#define LEX_L_PAREN 310
#define LEX_R_PAREN 311
#define LEX_DICT_INDIRECT 312
#define LEX_DICT 313
#define LEX_VAR 314
#define LEX_SELECTOR 315
#define LEX_IDENT 316
#define LEX_STRING 317
#define LEX_INT 318
#define LEX_REAL 319




/* Copy the first part of user declarations.  */
#line 46 "tengsyntax.yy"


// includes
#include <stdio.h>
#include <string>
#include <map>

#include "tengerror.h"
#include "tenginstruction.h"
#include "tengparsercontext.h"
#include "tengparservalue.h"
#include "tengformatter.h"
#include "tengcode.h"


using namespace std;

using namespace Teng;

namespace Teng {

// define left-value type
struct LeftValue_t {

    // element's left-value
    ParserValue_t val;

    // define option list type
    typedef map<string, string> OptionList_t;
    // teng-directive options used for building code
    OptionList_t opt;

    // define list of addresses info
    typedef vector<long> AddressList_t;
    // program address--tmp just for building code
    AddressList_t addr;

    // define identifier type
    typedef vector<string> Identifier_t;
    // variable identifier
    Identifier_t id;

    // position in input stream (just for lexical elements)
    // in other cases is pos-value irrelevant
    Error_t::Position_t pos;

    // program size in the time when the element was read (and then shifted)
    // this value is used for discarding parts of program in case of error
    unsigned int prgsize;
};

// left value type
#define YYSTYPE LeftValue_t
#define YYPARSE_PARAM context
#define YYLEX_PARAM context

// Cause the `yydebug' variable to be defined
//#define YYDEBUG 1

// verbose errors
#define YYERROR_VERBOSE

// define size of the parser stack
// (now, 200 is enough - grammar was fixed)
//#define YYINITDEPTH 200
// (default value 200 is too small for complex templates)
#define YYINITDEPTH 10000

// external function prototypes
extern int tengLex2_getElement(ParserValue_t &val,
        Error_t::Position_t &pos, Error_t &err);
extern int tengLex2_init(const string &str);
extern int tengLex2_finish();

// local function prototypes
static int yylex(YYSTYPE *leftValue, void *context);
static int yyerror(const char *msg);

// errlog function
static void printUnexpectedElement(ParserContext_t *context,
        int element, const YYSTYPE &leftValue);


// if enabled debug mode
#if YYDEBUG
// print element's semantic value
#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
static void yyprint(FILE *fp, int element, const YYSTYPE &leftValue);
#endif


// last error message (syntax or parse error)
// global variable -- ugly hack :-((
std::string tengSyntax_lastErrorMessage;


// max depth for templates included templates (looping protection)
#define MAX_INCLUDE_DEPTH 10

// macro for casting 'context' to the proper type
#define CONTEXT            (reinterpret_cast<ParserContext_t *> (context))

// macro for appending error class in actual context
// error levels are: DEBUG, WARNING, ERROR, FATAL
#define ERR(level, pos, msg)    do { \
                        (reinterpret_cast<ParserContext_t *> \
                        (context))->program->getErrors().logError( \
                        (Error_t::LL_##level), (pos), (msg)); \
                        } while (0)

// macros for byte-code generation
#define CODE(code)        do { \
                        tengCode_generate( \
                        (reinterpret_cast<ParserContext_t *> (context)), \
                        Instruction_t::code); \
                        } while (0)

#define CODE_VAL(code, val) \
                        do { \
                        tengCode_generate( \
                        (reinterpret_cast<ParserContext_t *> (context)), \
                        Instruction_t::code, val); \
                        } while (0)

#define CODE_VAL_VAR(opcode, val) \
                        do { \
                        tengCode_generate( \
                        (reinterpret_cast<ParserContext_t *> (context)), \
                        opcode, val); \
                        } while (0)

static inline void buildIdentifier(LeftValue_t &v) {
    v.val = ParserValue_t(); //clear
    for (LeftValue_t::Identifier_t::const_iterator i
             = v.id.begin(); i != v.id.end(); ++i)
        v.val.stringValue += "." + *i;
}

namespace {
    enum VariableName_t {
        VN_REGULAR,
        VN_COUNT,
        VN_NUMBER,
        VN_FIRST,
        VN_INNER,
        VN_LAST
    };

    struct VariableMapping_t {
        const char *name;
        VariableName_t variable;
        Instruction_t::OpCode_t opcode;
    };

    VariableMapping_t variableMapping[] = {
        {
            "_count",
            VN_COUNT,
            Instruction_t::FRAGCNT
        }, {
            "_number",
            VN_NUMBER,
            Instruction_t::FRAGITR
        }, {
            "_first",
            VN_FIRST,
            Instruction_t::FRAGFIRST
        }, {
            "_inner",
            VN_INNER,
            Instruction_t::FRAGINNER
        }, {
            "_last",
            VN_LAST,
            Instruction_t::FRAGLAST
        }, {
            0,
            VN_REGULAR,
            Instruction_t::VAR
        }
    };

    const VariableMapping_t& findVariableMapping(const std::string &name) {
        // ignore names not starting with underscore
        if (name.empty() || (name[0] != '_')) {
            return *(variableMapping +
                     (sizeof(variableMapping) / sizeof(VariableMapping_t))
                     - 1);
        }

        VariableMapping_t *sv = variableMapping;
        for ( ; sv->name; ++sv)
            if (!name.compare(sv->name)) return *sv;

        // not found
        return *sv;
    }
}

/** @short Generate code for variable.
 * @param result use $$ as this parameter
 * @param val value with variable name ($x).
 */
static inline void codeForVariable(void *context,
        LeftValue_t &result, LeftValue_t &val)
{
    // clear val and copy variable identifier
    result.val = ParserValue_t(); //clear
    result.id = val.id;
    result.val.stringValue = val.val.stringValue;

    // error indicator
    bool found = false;

    if (result.id.size() == 0) {
        // bad variable identifier -- code fake value
        ERR(ERROR, val.pos, "Invalid variable identifier "
            "in ${...} directive");
    } else {
        // identifier of variable/fragment
        Identifier_t id;

        const VariableMapping_t
            &varMapping(findVariableMapping(result.id.back()));

        switch (varMapping.variable) {
        case VN_COUNT:
            {
                // remove automatic variable name
                result.id.pop_back();

                // rebuild identifier
                buildIdentifier(result);

                // try to find fragment
                ParserContext_t::FragmentResolution_t fr =
                    CONTEXT->findFragment(&val.pos, result.id,
                                          result.val.stringValue, id, true);
                switch (fr) {
                case ParserContext_t::FR_NOT_FOUND:
                    // no-op -- we have nothing found
                    break;
                case ParserContext_t::FR_FOUND:
                    // fragment found
                    found = true;

                    CODE_VAL(FRAGCNT, result.val);
                    CONTEXT->program->back().identifier = id;
                    break;
                case ParserContext_t::FR_PARENT_FOUND:
                    // parent fragment found -- this fragment is not open
                    // and we must have some runtime overhead to find count
                    // of it
                    found = true;

                    CODE_VAL(XFRAGCNT, result.val);
                    CONTEXT->program->back().identifier = id;
                    break;
                }
            }
            break;

        case VN_NUMBER:
        case VN_FIRST:
        case VN_INNER:
        case VN_LAST:
            {
                // remove automatic variable name
                result.id.pop_back();

                // rebuild identifier
                buildIdentifier(result);

                // try to find fragment
                if (CONTEXT->findFragment(&val.pos, result.id,
                                          result.val.stringValue, id)) {
                    // we have found fragment
                    found = true;

                    // add instruction
                    CODE_VAL_VAR(varMapping.opcode, result.val);
                    CONTEXT->program->back().identifier = id;
                }
            }
            break;

        default:
            // find fragment for this variable
            if (CONTEXT->findFragmentForVariable(val.pos, result.id,
                    result.val.stringValue, id)) {
                // variable found
                found = true;

                // generate code for variable
                result.val.integerValue = 1; //escape
                CODE_VAL(VAR, result.val);

                // add identifier
                CONTEXT->program->back().identifier = id;
            }
        }
    }

    if (!found) {
        // no such varibale or fragment => generate code for undefined value
        result.val.setString("undefined");
        CODE_VAL(VAL, result.val);
    }
}



/* Enabling traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif

/* Enabling verbose error messages.  */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif

/* Enabling the token table.  */
#ifndef YYTOKEN_TABLE
# define YYTOKEN_TABLE 1
#endif

#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif



/* Copy the second part of user declarations.  */


/* Line 216 of yacc.c.  */
#line 554 "tengsyntax.cc"

#ifdef short
# undef short
#endif

#ifdef YYTYPE_UINT8
typedef YYTYPE_UINT8 yytype_uint8;
#else
typedef unsigned char yytype_uint8;
#endif

#ifdef YYTYPE_INT8
typedef YYTYPE_INT8 yytype_int8;
#elif (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
typedef signed char yytype_int8;
#else
typedef short int yytype_int8;
#endif

#ifdef YYTYPE_UINT16
typedef YYTYPE_UINT16 yytype_uint16;
#else
typedef unsigned short int yytype_uint16;
#endif

#ifdef YYTYPE_INT16
typedef YYTYPE_INT16 yytype_int16;
#else
typedef short int yytype_int16;
#endif

#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
#  define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
#  define YYSIZE_T size_t
# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  define YYSIZE_T size_t
# else
#  define YYSIZE_T unsigned int
# endif
#endif

#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)

#ifndef YY_
# if YYENABLE_NLS
#  if ENABLE_NLS
#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
#   define YY_(msgid) dgettext ("bison-runtime", msgid)
#  endif
# endif
# ifndef YY_
#  define YY_(msgid) msgid
# endif
#endif

/* Suppress unused-variable warnings by "using" E.  */
#if ! defined lint || defined __GNUC__
# define YYUSE(e) ((void) (e))
#else
# define YYUSE(e) /* empty */
#endif

/* Identity function, used to suppress warnings about constant conditions.  */
#ifndef lint
# define YYID(n) (n)
#else
#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static int
YYID (int i)
#else
static int
YYID (i)
    int i;
#endif
{
  return i;
}
#endif

#if ! defined yyoverflow || YYERROR_VERBOSE

/* The parser invokes alloca or malloc; define the necessary symbols.  */

# ifdef YYSTACK_USE_ALLOCA
#  if YYSTACK_USE_ALLOCA
#   ifdef __GNUC__
#    define YYSTACK_ALLOC __builtin_alloca
#   elif defined __BUILTIN_VA_ARG_INCR
#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
#   elif defined _AIX
#    define YYSTACK_ALLOC __alloca
#   elif defined _MSC_VER
#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
#    define alloca _alloca
#   else
#    define YYSTACK_ALLOC alloca
#    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#     ifndef _STDLIB_H
#      define _STDLIB_H 1
#     endif
#    endif
#   endif
#  endif
# endif

# ifdef YYSTACK_ALLOC
   /* Pacify GCC's `empty if-body' warning.  */
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
#  ifndef YYSTACK_ALLOC_MAXIMUM
    /* The OS might guarantee only one guard page at the bottom of the stack,
       and a page size can be as small as 4096 bytes.  So we cannot safely
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
       to allow for a few compiler-allocated temporary stack slots.  */
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
#  endif
# else
#  define YYSTACK_ALLOC YYMALLOC
#  define YYSTACK_FREE YYFREE
#  ifndef YYSTACK_ALLOC_MAXIMUM
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
#  endif
#  if (defined __cplusplus && ! defined _STDLIB_H \
       && ! ((defined YYMALLOC || defined malloc) \
	     && (defined YYFREE || defined free)))
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#   ifndef _STDLIB_H
#    define _STDLIB_H 1
#   endif
#  endif
#  ifndef YYMALLOC
#   define YYMALLOC malloc
#   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
#   endif
#  endif
#  ifndef YYFREE
#   define YYFREE free
#   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
void free (void *); /* INFRINGES ON USER NAME SPACE */
#   endif
#  endif
# endif
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */


#if (! defined yyoverflow \
     && (! defined __cplusplus \
	 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))

/* A type that is properly aligned for any stack member.  */
union yyalloc
{
  yytype_int16 yyss;
  YYSTYPE yyvs;
  };

/* The size of the maximum gap between one aligned stack and the next.  */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)

/* The size of an array large to enough to hold all stacks, each with
   N elements.  */
# define YYSTACK_BYTES(N) \
     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
      + YYSTACK_GAP_MAXIMUM)

/* Copy COUNT objects from FROM to TO.  The source and destination do
   not overlap.  */
# ifndef YYCOPY
#  if defined __GNUC__ && 1 < __GNUC__
#   define YYCOPY(To, From, Count) \
      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
#  else
#   define YYCOPY(To, From, Count)		\
      do					\
	{					\
	  YYSIZE_T yyi;				\
	  for (yyi = 0; yyi < (Count); yyi++)	\
	    (To)[yyi] = (From)[yyi];		\
	}					\
      while (YYID (0))
#  endif
# endif

/* Relocate STACK from its old location to the new one.  The
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
   elements in the stack, and YYPTR gives the new location of the
   stack.  Advance YYPTR to a properly aligned location for the next
   stack.  */
# define YYSTACK_RELOCATE(Stack)					\
    do									\
      {									\
	YYSIZE_T yynewbytes;						\
	YYCOPY (&yyptr->Stack, Stack, yysize);				\
	Stack = &yyptr->Stack;						\
	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
	yyptr += yynewbytes / sizeof (*yyptr);				\
      }									\
    while (YYID (0))

#endif

/* YYFINAL -- State number of the termination state.  */
#define YYFINAL  4
/* YYLAST -- Last index in YYTABLE.  */
#define YYLAST   1094

/* YYNTOKENS -- Number of terminals.  */
#define YYNTOKENS  65
/* YYNNTS -- Number of nonterminals.  */
#define YYNNTS  87
/* YYNRULES -- Number of rules.  */
#define YYNRULES  184
/* YYNRULES -- Number of states.  */
#define YYNSTATES  337

/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
#define YYUNDEFTOK  2
#define YYMAXUTOK   319

#define YYTRANSLATE(YYX)						\
  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)

/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
static const yytype_uint8 yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
      55,    56,    57,    58,    59,    60,    61,    62,    63,    64
};

#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
   YYRHS.  */
static const yytype_uint16 yyprhs[] =
{
       0,     0,     3,     5,     7,    10,    13,    14,    16,    18,
      20,    22,    24,    26,    28,    30,    32,    34,    36,    38,
      42,    45,    48,    51,    52,    56,    61,    62,    66,    67,
      72,    73,    81,    82,    90,    91,    97,    98,   103,   104,
     112,   113,   121,   122,   128,   129,   134,   141,   142,   150,
     151,   158,   159,   164,   165,   166,   176,   177,   178,   179,
     190,   191,   197,   198,   204,   205,   210,   211,   216,   217,
     222,   223,   224,   225,   234,   235,   236,   237,   238,   247,
     251,   255,   259,   260,   265,   266,   271,   275,   276,   281,
     282,   290,   291,   299,   300,   306,   307,   312,   316,   320,
     324,   328,   332,   336,   340,   344,   348,   352,   353,   358,
     359,   364,   368,   372,   376,   380,   384,   388,   392,   396,
     400,   404,   405,   406,   414,   417,   420,   421,   425,   426,
     430,   433,   436,   439,   441,   443,   445,   447,   449,   450,
     455,   457,   459,   461,   463,   465,   468,   470,   471,   473,
     476,   478,   481,   485,   486,   494,   495,   503,   504,   510,
     511,   512,   519,   523,   524,   528,   529,   531,   534,   537,
     540,   543,   545,   549,   554,   555,   561,   566,   567,   573,
     578,   579,   585,   589,   591
};

/* YYRHS -- A `-1'-separated list of the rules' RHS.  */
static const yytype_int16 yyrhs[] =
{
      66,     0,    -1,    67,    -1,     1,    -1,    67,     3,    -1,
      67,    68,    -1,    -1,    69,    -1,    70,    -1,    71,    -1,
      75,    -1,    77,    -1,    82,    -1,    91,    -1,    87,    -1,
     109,    -1,   112,    -1,   114,    -1,   119,    -1,    17,     1,
      18,    -1,     4,    72,    -1,     5,    72,    -1,    74,    18,
      -1,    -1,     1,    73,    18,    -1,    61,    25,    62,    74,
      -1,    -1,     6,    74,    18,    -1,    -1,     6,     1,    76,
      18,    -1,    -1,     7,    74,    18,    78,    67,     8,    72,
      -1,    -1,     7,     1,    79,    18,    67,     8,    72,    -1,
      -1,     7,     1,    80,     8,    72,    -1,    -1,     1,    81,
       8,    72,    -1,    -1,     9,   132,    18,    83,    67,    10,
      72,    -1,    -1,     9,     1,    84,    18,    67,    10,    72,
      -1,    -1,     9,     1,    85,    10,    72,    -1,    -1,     1,
      86,    10,    72,    -1,    15,   131,   132,    25,   120,    18,
      -1,    -1,    15,   131,   132,    25,     1,    88,    18,    -1,
      -1,    15,     1,    89,    25,   120,    18,    -1,    -1,    15,
       1,    90,    18,    -1,    -1,    -1,    11,   120,    18,    92,
      67,    93,   101,    14,    72,    -1,    -1,    -1,    -1,    11,
       1,    94,    18,    95,    67,    96,   101,    14,    72,    -1,
      -1,    11,     1,    97,    14,    72,    -1,    -1,     1,    98,
      12,     1,    18,    -1,    -1,     1,    99,    13,    72,    -1,
      -1,     1,   100,    14,    72,    -1,    -1,    13,    72,   102,
      67,    -1,    -1,    -1,    -1,    12,   103,   120,    18,   104,
      67,   105,   101,    -1,    -1,    -1,    -1,    -1,    12,     1,
     106,    18,   107,    67,   108,   101,    -1,    16,   120,    18,
      -1,    19,   120,    21,    -1,    19,   132,    21,    -1,    -1,
      16,     1,   110,    18,    -1,    -1,    19,     1,   111,    21,
      -1,    20,   128,    21,    -1,    -1,    20,     1,   113,    21,
      -1,    -1,    22,    62,    18,   115,    67,    23,    72,    -1,
      -1,    22,     1,   116,    18,    67,    23,    72,    -1,    -1,
      22,     1,   117,    23,    72,    -1,    -1,     1,   118,    23,
      72,    -1,    24,   132,    18,    -1,    55,   120,    56,    -1,
     120,    37,   120,    -1,   120,    36,   120,    -1,   120,    41,
     120,    -1,   120,    40,   120,    -1,   120,    39,   120,    -1,
     120,    38,   120,    -1,   120,    35,   120,    -1,   120,    34,
     120,    -1,    -1,   120,    29,   121,   120,    -1,    -1,   120,
      30,   122,   120,    -1,   120,    31,   120,    -1,   120,    32,
     120,    -1,   120,    33,   120,    -1,   120,    44,   120,    -1,
     120,    43,   120,    -1,   120,    42,   120,    -1,   120,    48,
     120,    -1,   120,    47,   120,    -1,   120,    46,   120,    -1,
     120,    45,   120,    -1,    -1,    -1,   120,    28,   123,   120,
      27,   124,   120,    -1,    51,   120,    -1,    50,   120,    -1,
      -1,    43,   125,   120,    -1,    -1,    44,   126,   120,    -1,
      58,   128,    -1,    57,   120,    -1,    59,   132,    -1,   129,
      -1,   134,    -1,   145,    -1,   147,    -1,   149,    -1,    -1,
      55,     1,   127,    56,    -1,    61,    -1,   130,    -1,    63,
      -1,    64,    -1,    62,    -1,    62,   130,    -1,    59,    -1,
      -1,    61,    -1,    61,   133,    -1,   133,    -1,    60,    61,
      -1,    60,    61,   133,    -1,    -1,    52,    55,   120,    26,
     135,   138,    56,    -1,    -1,    52,    55,     1,   136,    26,
     138,    56,    -1,    -1,    52,    55,     1,   137,    56,    -1,
      -1,    -1,   144,    27,   139,   120,   140,   141,    -1,    48,
      27,   120,    -1,    -1,    26,   142,   138,    -1,    -1,   129,
      -1,    44,    63,    -1,    44,    64,    -1,    43,    63,    -1,
      43,    64,    -1,   143,    -1,   143,    26,   144,    -1,    53,
      55,   132,    56,    -1,    -1,    53,    55,     1,   146,    56,
      -1,    54,    55,   132,    56,    -1,    -1,    54,    55,     1,
     148,    56,    -1,    61,    55,   151,    56,    -1,    -1,    61,
      55,     1,   150,    56,    -1,   120,    26,   151,    -1,   120,
      -1,    -1
};

/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
static const yytype_uint16 yyrline[] =
{
       0,   446,   446,   452,   468,   474,   475,   480,   481,   482,
     483,   484,   485,   486,   487,   488,   489,   490,   491,   496,
     505,   513,   521,   530,   529,   543,   550,   557,   590,   589,
     604,   603,   647,   646,   656,   655,   670,   669,   693,   692,
     726,   725,   740,   739,   754,   753,   773,   811,   809,   826,
     825,   840,   839,   857,   863,   856,   886,   896,   901,   885,
     911,   910,   926,   925,   942,   941,   958,   957,   978,   977,
     989,   995,  1000,   988,  1015,  1021,  1030,  1035,  1020,  1047,
    1051,  1055,  1065,  1064,  1082,  1081,  1101,  1108,  1107,  1129,
    1128,  1157,  1156,  1166,  1165,  1180,  1179,  1198,  1222,  1226,
    1232,  1239,  1245,  1252,  1258,  1265,  1271,  1279,  1278,  1295,
    1294,  1310,  1316,  1322,  1328,  1334,  1340,  1346,  1352,  1358,
    1364,  1371,  1376,  1370,  1394,  1400,  1407,  1406,  1419,  1418,
    1430,  1435,  1441,  1448,  1454,  1458,  1462,  1466,  1473,  1472,
    1493,  1515,  1519,  1523,  1531,  1535,  1544,  1546,  1556,  1566,
    1634,  1648,  1654,  1675,  1674,  1697,  1696,  1714,  1713,  1734,
    1739,  1733,  1752,  1762,  1761,  1773,  1788,  1793,  1798,  1803,
    1808,  1816,  1828,  1850,  1907,  1906,  1927,  1991,  1990,  2012,
    2024,  2023,  2044,  2048,  2053
};
#endif

#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
static const char *const yytname[] =
{
  "$end", "error", "$undefined", "LEX_TEXT", "LEX_DEBUG", "LEX_BYTECODE",
  "LEX_INCLUDE", "LEX_FORMAT", "LEX_ENDFORMAT", "LEX_FRAGMENT",
  "LEX_ENDFRAGMENT", "LEX_IF", "LEX_ELSEIF", "LEX_ELSE", "LEX_ENDIF",
  "LEX_SET", "LEX_EXPR", "LEX_TENG", "LEX_END", "LEX_SHORT_EXPR",
  "LEX_SHORT_DICT", "LEX_SHORT_END", "LEX_CTYPE", "LEX_ENDCTYPE",
  "LEX_REPEATFRAG", "LEX_ASSIGN", "LEX_COMMA", "LEX_COLON",
  "LEX_COND_EXPR", "LEX_OR", "LEX_AND", "LEX_BITOR", "LEX_BITXOR",
  "LEX_BITAND", "LEX_STR_NE", "LEX_STR_EQ", "LEX_NE", "LEX_EQ", "LEX_LT",
  "LEX_GT", "LEX_LE", "LEX_GE", "LEX_CONCAT", "LEX_SUB", "LEX_ADD",
  "LEX_REPEAT", "LEX_MOD", "LEX_DIV", "LEX_MUL", "LEX_UNARY", "LEX_BITNOT",
  "LEX_NOT", "LEX_CASE", "LEX_DEFINED", "LEX_EXIST", "LEX_L_PAREN",
  "LEX_R_PAREN", "LEX_DICT_INDIRECT", "LEX_DICT", "LEX_VAR",
  "LEX_SELECTOR", "LEX_IDENT", "LEX_STRING", "LEX_INT", "LEX_REAL",
  "$accept", "start", "template", "teng_directive", "teng_unknown",
  "teng_debug", "teng_bytecode", "no_options_LEX_END", "@1", "options",
  "teng_include", "@2", "teng_format", "@3", "@4", "@5", "@6",
  "teng_fragment", "@7", "@8", "@9", "@10", "teng_set", "@11", "@12",
  "@13", "teng_if", "@14", "@15", "@16", "@17", "@18", "@19", "@20", "@21",
  "@22", "teng_else", "@23", "@24", "@25", "@26", "@27", "@28", "@29",
  "teng_expr", "@30", "@31", "teng_dict", "@32", "teng_ctype", "@33",
  "@34", "@35", "@36", "teng_repeatfrag", "expression", "@37", "@38",
  "@39", "@40", "@41", "@42", "@43", "dictionary_item", "value_literal",
  "string_literal", "voluntary_dollar_before_var", "variable_identifier",
  "dot_variable", "case", "@44", "@45", "@46", "case_options", "@47",
  "@48", "case_more_options", "@49", "case_literal", "case_values",
  "defined", "@50", "exist", "@51", "function", "@52",
  "function_arguments", 0
};
#endif

# ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
   token YYLEX-NUM.  */
static const yytype_uint16 yytoknum[] =
{
       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
     285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
     295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
     305,   306,   307,   308,   309,   310,   311,   312,   313,   314,
     315,   316,   317,   318,   319
};
# endif

/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
static const yytype_uint8 yyr1[] =
{
       0,    65,    66,    66,    67,    67,    67,    68,    68,    68,
      68,    68,    68,    68,    68,    68,    68,    68,    68,    69,
      70,    71,    72,    73,    72,    74,    74,    75,    76,    75,
      78,    77,    79,    77,    80,    77,    81,    77,    83,    82,
      84,    82,    85,    82,    86,    82,    87,    88,    87,    89,
      87,    90,    87,    92,    93,    91,    94,    95,    96,    91,
      97,    91,    98,    91,    99,    91,   100,    91,   102,   101,
     103,   104,   105,   101,   101,   106,   107,   108,   101,   109,
     109,   109,   110,   109,   111,   109,   112,   113,   112,   115,
     114,   116,   114,   117,   114,   118,   114,   119,   120,   120,
     120,   120,   120,   120,   120,   120,   120,   121,   120,   122,
     120,   120,   120,   120,   120,   120,   120,   120,   120,   120,
     120,   123,   124,   120,   120,   120,   125,   120,   126,   120,
     120,   120,   120,   120,   120,   120,   120,   120,   127,   120,
     128,   129,   129,   129,   130,   130,   131,   131,   132,   132,
     132,   133,   133,   135,   134,   136,   134,   137,   134,   139,
     140,   138,   138,   142,   141,   141,   143,   143,   143,   143,
     143,   144,   144,   145,   146,   145,   147,   148,   147,   149,
     150,   149,   151,   151,   151
};

/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
static const yytype_uint8 yyr2[] =
{
       0,     2,     1,     1,     2,     2,     0,     1,     1,     1,
       1,     1,     1,     1,     1,     1,     1,     1,     1,     3,
       2,     2,     2,     0,     3,     4,     0,     3,     0,     4,
       0,     7,     0,     7,     0,     5,     0,     4,     0,     7,
       0,     7,     0,     5,     0,     4,     6,     0,     7,     0,
       6,     0,     4,     0,     0,     9,     0,     0,     0,    10,
       0,     5,     0,     5,     0,     4,     0,     4,     0,     4,
       0,     0,     0,     8,     0,     0,     0,     0,     8,     3,
       3,     3,     0,     4,     0,     4,     3,     0,     4,     0,
       7,     0,     7,     0,     5,     0,     4,     3,     3,     3,
       3,     3,     3,     3,     3,     3,     3,     0,     4,     0,
       4,     3,     3,     3,     3,     3,     3,     3,     3,     3,
       3,     0,     0,     7,     2,     2,     0,     3,     0,     3,
       2,     2,     2,     1,     1,     1,     1,     1,     0,     4,
       1,     1,     1,     1,     1,     2,     1,     0,     1,     2,
       1,     2,     3,     0,     7,     0,     7,     0,     5,     0,
       0,     6,     3,     0,     3,     0,     1,     2,     2,     2,
       2,     1,     3,     4,     0,     5,     4,     0,     5,     4,
       0,     5,     3,     1,     0
};

/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
   means the default is an error.  */
static const yytype_uint8 yydefact[] =
{
       0,     3,     0,     0,     1,    36,     4,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       5,     7,     8,     9,    10,    11,    12,    14,    13,    15,
      16,    17,    18,     0,     0,     0,     0,     0,     0,    23,
       0,    20,     0,    21,    28,     0,    32,     0,    40,     0,
     148,     0,   150,    56,   126,   128,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,   144,   142,   143,     0,
     133,   141,   134,   135,   136,   137,    49,   146,     0,    82,
       0,     0,    84,   148,     0,     0,    87,   140,     0,    91,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
      22,     0,    27,     0,     0,    30,     0,     0,   151,   149,
      38,     0,     0,     0,     0,   125,   124,     0,     0,     0,
     138,     0,   131,   130,   132,     0,   145,    53,   121,   107,
     109,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,    79,    19,     0,    80,    81,     0,    86,
       0,     0,    89,    97,    37,    45,     0,    65,    67,    96,
      24,    26,    29,     6,     0,     6,     6,     0,   152,     6,
      57,     0,   127,   129,   155,     0,   174,     0,   177,     0,
       0,    98,   180,   183,     0,     6,     0,     0,     0,   111,
     112,   113,   106,   105,   100,    99,   104,   103,   102,   101,
     116,   115,   114,   120,   119,   118,   117,     0,    52,     0,
      83,    85,    88,     6,     0,     6,    63,    25,     0,    35,
       0,     0,    43,     0,     6,    61,     0,     0,   153,     0,
     173,     0,   176,   139,     0,   184,   179,     0,     0,   108,
     110,     0,    47,     0,     0,    94,     0,     0,     0,     0,
       0,     0,     0,   158,     0,   175,   178,   181,   182,    74,
     122,    50,     0,    46,     0,     0,    33,    31,    41,    39,
      74,     0,     0,     0,   166,     0,   171,     0,     0,     0,
       0,     0,     0,    48,    92,    90,     0,   169,   170,   167,
     168,     0,   156,     0,   159,   154,    75,     0,    68,     0,
     123,     0,   162,   172,     0,     0,     0,     6,    55,    59,
     160,    76,    71,     0,   165,     6,     6,   163,   161,     0,
       0,     0,    74,    74,   164,    78,    73
};

/* YYDEFGOTO[NTERM-NUM].  */
static const yytype_int16 yydefgoto[] =
{
      -1,     2,     3,    20,    21,    22,    23,    41,    98,    42,
      24,   101,    25,   175,   103,   104,    33,    26,   179,   106,
     107,    34,    27,   272,   149,   150,    28,   195,   269,   111,
     234,   280,   112,    35,    36,    37,   291,   317,   307,   326,
     333,   315,   325,   332,    29,   152,   155,    30,   158,    31,
     225,   160,   161,    38,    32,   193,   197,   198,   196,   292,
     113,   114,   190,    88,    70,    71,    78,    51,    52,    72,
     264,   236,   237,   285,   314,   324,   328,   331,   286,   287,
      73,   239,    74,   241,    75,   244,   194
};

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
#define YYPACT_NINF -277
static const yytype_int16 yypact[] =
{
     269,  -277,    26,   628,  -277,    88,  -277,    17,    17,    19,
      20,    14,   256,     5,   278,    27,   140,    32,     1,   -11,
    -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,
    -277,  -277,  -277,    28,    36,    18,    38,    47,    49,  -277,
      54,  -277,    76,  -277,  -277,    81,    95,    91,   100,    51,
      80,   135,  -277,   141,  -277,  -277,   922,   922,   101,   102,
     103,   301,   922,    98,   -11,   105,    99,  -277,  -277,   405,
    -277,  -277,  -277,  -277,  -277,  -277,   146,  -277,   -11,  -277,
     436,   147,  -277,   -33,   579,   151,  -277,  -277,   153,   144,
     150,   157,    17,    17,   175,    17,    17,    17,   159,   116,
    -277,   161,  -277,   162,   173,  -277,   164,   176,    80,  -277,
    -277,   167,   182,   922,   922,  -277,  -277,   323,    22,    30,
    -277,   550,  -277,  -277,  -277,   170,  -277,  -277,  -277,  -277,
    -277,   922,   922,   922,   922,   922,   922,   922,   922,   922,
     922,   922,   922,   922,   922,   922,   922,   922,   922,   180,
     188,   184,   189,  -277,  -277,   190,  -277,  -277,   191,  -277,
     197,   194,  -277,  -277,  -277,  -277,   200,  -277,  -277,  -277,
    -277,   158,  -277,  -277,    17,  -277,  -277,    17,  -277,  -277,
    -277,    17,  -277,  -277,   174,   871,  -277,   179,  -277,   181,
     183,  -277,  -277,   894,   185,  -277,   922,   922,   922,  1015,
    1031,  1046,   104,   104,   104,   104,    73,    73,    73,    73,
      -6,    -6,    -6,  -277,  -277,  -277,  -277,   922,  -277,   345,
    -277,  -277,  -277,  -277,    17,  -277,  -277,  -277,   738,  -277,
     760,   782,  -277,   804,  -277,  -277,   210,   186,  -277,   187,
    -277,   192,  -277,  -277,   198,   922,  -277,   650,   916,   979,
     998,   467,  -277,   498,   826,  -277,   850,    17,    17,    17,
      17,   672,   -19,  -277,   -19,  -277,  -277,  -277,  -277,    42,
    -277,  -277,   220,  -277,    17,    17,  -277,  -277,  -277,  -277,
      42,     6,    43,   213,  -277,   199,   218,   219,   202,   367,
      17,   231,   922,  -277,  -277,  -277,   233,  -277,  -277,  -277,
    -277,   922,  -277,    33,  -277,  -277,  -277,   922,  -277,    17,
     959,    17,   959,  -277,   922,   235,   529,  -277,  -277,  -277,
     959,  -277,  -277,   874,   230,  -277,  -277,  -277,  -277,   694,
     716,   -19,    42,    42,  -277,  -277,  -277
};

/* YYPGOTO[NTERM-NUM].  */
static const yytype_int16 yypgoto[] =
{
    -277,  -277,  -163,  -277,  -277,  -277,  -277,    -8,  -277,    -1,
    -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,
    -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,
    -277,  -277,  -277,  -277,  -277,  -277,  -276,  -277,  -277,  -277,
    -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,  -277,
    -277,  -277,  -277,  -277,  -277,    -9,  -277,  -277,  -277,  -277,
    -277,  -277,  -277,   196,  -245,   195,  -277,    -5,   -16,  -277,
    -277,  -277,  -277,  -263,  -277,  -277,  -277,  -277,  -277,   -43,
    -277,  -277,  -277,  -277,  -277,  -277,    23
};

/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
   positive, shift that token.  If negative, reduce the rule which
   number is the opposite.  If zero, do what YYDEFACT says.
   If YYTABLE_NINF, syntax error.  */
#define YYTABLE_NINF -185
static const yytype_int16 yytable[] =
{
      43,   288,    89,    69,   296,    80,    76,    84,    45,    47,
     228,    85,   230,   231,    91,    48,   233,   284,    39,   284,
      44,    46,   125,   186,   281,   282,     4,    49,    81,   283,
      94,   188,   247,    86,   109,   -26,    92,   -26,   -26,   145,
     146,   147,   148,    66,    67,    68,    93,   115,   116,    49,
      50,    95,   121,   122,   289,   290,   335,   336,   284,   124,
     254,    96,   256,    90,    77,  -147,  -147,   109,   334,   297,
     298,   261,    97,   151,    49,    50,   281,   282,    40,    99,
      40,    40,    49,    50,   164,   165,   284,   167,   168,   169,
      49,    50,   178,    87,   100,    66,    67,    68,   -44,   102,
     -62,   -64,   -66,   -34,   182,   183,   299,   300,   185,   105,
     -42,   -95,   108,   187,   189,   142,   143,   144,   145,   146,
     147,   148,   199,   200,   201,   202,   203,   204,   205,   206,
     207,   208,   209,   210,   211,   212,   213,   214,   215,   216,
      49,    82,   138,   139,   140,   141,   142,   143,   144,   145,
     146,   147,   148,   110,   323,   -60,   117,   118,   119,    87,
     125,    66,   329,   330,   -51,   154,   229,   -93,   162,   232,
     227,   192,   157,   235,   159,   163,   166,   170,   171,   172,
     173,   174,   176,    54,    55,   180,   177,   248,   249,   250,
      56,    57,    58,    59,    60,    61,   181,    62,    63,    64,
      49,    83,    66,    67,    68,   217,   218,   220,   251,   219,
     253,   221,   222,    54,    55,   223,   255,   224,   226,    40,
      56,    57,    58,    59,    60,    61,  -184,    62,    63,    64,
    -157,    65,    66,    67,    68,   240,   262,   242,   293,   243,
     301,   246,   263,   265,   303,   309,   304,   311,   266,   276,
     277,   278,   279,   321,   267,   302,   327,    53,   305,   123,
     313,   126,     0,     0,     0,     0,   294,   295,   268,    -6,
       1,     0,    -6,    -6,    -6,    -6,    -6,     0,    -6,    79,
      -6,     0,   308,   310,    -6,    -6,    -6,     0,    -6,    -6,
       0,    -6,   312,    -6,     0,     0,     0,     0,   316,    54,
      55,   318,   120,   319,     0,   320,    56,    57,    58,    59,
      60,    61,     0,    62,    63,    64,     0,    65,    66,    67,
      68,    54,    55,     0,   184,     0,     0,     0,    56,    57,
      58,    59,    60,    61,     0,    62,    63,    64,     0,    65,
      66,    67,    68,     0,    54,    55,   252,     0,     0,     0,
       0,    56,    57,    58,    59,    60,    61,     0,    62,    63,
      64,     0,    65,    66,    67,    68,    54,    55,   306,     0,
       0,     0,     0,    56,    57,    58,    59,    60,    61,     0,
      62,    63,    64,     0,    65,    66,    67,    68,    54,    55,
       0,     0,     0,     0,     0,    56,    57,    58,    59,    60,
      61,     0,    62,    63,    64,     0,    65,    66,    67,    68,
     -70,   -70,     0,     0,     0,     0,     0,   -70,   -70,   -70,
     -70,   -70,   -70,   127,   -70,   -70,   -70,     0,   -70,   -70,
     -70,   -70,     0,   128,   129,   130,   131,   132,   133,   134,
     135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
     145,   146,   147,   148,   153,     0,     0,     0,     0,     0,
       0,     0,     0,     0,   128,   129,   130,   131,   132,   133,
     134,   135,   136,   137,   138,   139,   140,   141,   142,   143,
     144,   145,   146,   147,   148,   271,     0,     0,     0,     0,
       0,     0,     0,     0,     0,   128,   129,   130,   131,   132,
     133,   134,   135,   136,   137,   138,   139,   140,   141,   142,
     143,   144,   145,   146,   147,   148,   273,     0,     0,     0,
       0,     0,     0,     0,     0,     0,   128,   129,   130,   131,
     132,   133,   134,   135,   136,   137,   138,   139,   140,   141,
     142,   143,   144,   145,   146,   147,   148,   322,     0,     0,
       0,     0,     0,     0,     0,     0,     0,   128,   129,   130,
     131,   132,   133,   134,   135,   136,   137,   138,   139,   140,
     141,   142,   143,   144,   145,   146,   147,   148,   128,   129,
     130,   131,   132,   133,   134,   135,   136,   137,   138,   139,
     140,   141,   142,   143,   144,   145,   146,   147,   148,     0,
     156,     0,     0,     0,     0,     0,   191,   128,   129,   130,
     131,   132,   133,   134,   135,   136,   137,   138,   139,   140,
     141,   142,   143,   144,   145,   146,   147,   148,    -2,     5,
       0,     6,     7,     8,     9,    10,     0,    11,     0,    12,
       0,     0,     0,    13,    14,    15,     0,    16,    17,     0,
      18,     5,    19,     6,     7,     8,     9,    10,     0,    11,
       0,    12,   -54,   -54,   -54,    13,    14,    15,     0,    16,
      17,     0,    18,     5,    19,     6,     7,     8,     9,    10,
       0,    11,     0,    12,   -58,   -58,   -58,    13,    14,    15,
       0,    16,    17,     0,    18,     5,    19,     6,     7,     8,
       9,    10,     0,    11,     0,    12,   -77,   -77,   -77,    13,
      14,    15,     0,    16,    17,     0,    18,     5,    19,     6,
       7,     8,     9,    10,     0,    11,     0,    12,   -72,   -72,
     -72,    13,    14,    15,     0,    16,    17,     0,    18,     5,
      19,     6,     7,     8,     9,    10,   257,    11,     0,    12,
       0,     0,     0,    13,    14,    15,     0,    16,    17,     0,
      18,     5,    19,     6,     7,     8,     9,    10,   258,    11,
       0,    12,     0,     0,     0,    13,    14,    15,     0,    16,
      17,     0,    18,     5,    19,     6,     7,     8,     9,    10,
       0,    11,   259,    12,     0,     0,     0,    13,    14,    15,
       0,    16,    17,     0,    18,     5,    19,     6,     7,     8,
       9,    10,     0,    11,   260,    12,     0,     0,     0,    13,
      14,    15,     0,    16,    17,     0,    18,     5,    19,     6,
       7,     8,     9,    10,     0,    11,     0,    12,     0,     0,
       0,    13,    14,    15,     0,    16,    17,     0,    18,   274,
      19,     5,     0,     6,     7,     8,     9,    10,     0,    11,
       0,    12,     0,     0,     0,    13,    14,    15,     0,    16,
      17,     0,    18,   275,    19,     5,     0,     6,     7,     8,
       9,    10,     0,    11,     0,    12,     0,     0,   -69,    13,
      14,    15,     0,    16,    17,     0,    18,   238,    19,   128,
     129,   130,   131,   132,   133,   134,   135,   136,   137,   138,
     139,   140,   141,   142,   143,   144,   145,   146,   147,   148,
     245,     0,   128,   129,   130,   131,   132,   133,   134,   135,
     136,   137,   138,   139,   140,   141,   142,   143,   144,   145,
     146,   147,   148,   270,   128,   129,   130,   131,   132,   133,
     134,   135,   136,   137,   138,   139,   140,   141,   142,   143,
     144,   145,   146,   147,   148,    54,    55,     0,     0,     0,
       0,     0,    56,    57,    58,    59,    60,    61,     0,    62,
      63,    64,     0,    65,    66,    67,    68,   128,   129,   130,
     131,   132,   133,   134,   135,   136,   137,   138,   139,   140,
     141,   142,   143,   144,   145,   146,   147,   148,   129,   130,
     131,   132,   133,   134,   135,   136,   137,   138,   139,   140,
     141,   142,   143,   144,   145,   146,   147,   148,   130,   131,
     132,   133,   134,   135,   136,   137,   138,   139,   140,   141,
     142,   143,   144,   145,   146,   147,   148,   132,   133,   134,
     135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
     145,   146,   147,   148,   133,   134,   135,   136,   137,   138,
     139,   140,   141,   142,   143,   144,   145,   146,   147,   148,
     134,   135,   136,   137,   138,   139,   140,   141,   142,   143,
     144,   145,   146,   147,   148
};

static const yytype_int16 yycheck[] =
{
       8,   264,     1,    12,   280,    14,     1,    16,     9,    10,
     173,    16,   175,   176,    19,     1,   179,   262,     1,   264,
       1,     1,    55,     1,    43,    44,     0,    60,     1,    48,
      12,     1,   195,     1,    50,    18,     8,    18,    18,    45,
      46,    47,    48,    62,    63,    64,    10,    56,    57,    60,
      61,    13,    61,    62,    12,    13,   332,   333,   303,    64,
     223,    14,   225,    62,    59,    60,    61,    83,   331,    63,
      64,   234,    23,    78,    60,    61,    43,    44,    61,    25,
      61,    61,    60,    61,    92,    93,   331,    95,    96,    97,
      60,    61,   108,    61,    18,    62,    63,    64,    10,    18,
      12,    13,    14,     8,   113,   114,    63,    64,   117,    18,
      10,    23,    61,   118,   119,    42,    43,    44,    45,    46,
      47,    48,   131,   132,   133,   134,   135,   136,   137,   138,
     139,   140,   141,   142,   143,   144,   145,   146,   147,   148,
      60,     1,    38,    39,    40,    41,    42,    43,    44,    45,
      46,    47,    48,    18,   317,    14,    55,    55,    55,    61,
      55,    62,   325,   326,    18,    18,   174,    23,    18,   177,
     171,     1,    21,   181,    21,    18,     1,    18,    62,    18,
      18,     8,    18,    43,    44,    18,    10,   196,   197,   198,
      50,    51,    52,    53,    54,    55,    14,    57,    58,    59,
      60,    61,    62,    63,    64,    25,    18,    18,   217,    25,
     219,    21,    21,    43,    44,    18,   224,    23,    18,    61,
      50,    51,    52,    53,    54,    55,    56,    57,    58,    59,
      56,    61,    62,    63,    64,    56,    26,    56,    18,    56,
      27,    56,    56,    56,    26,    14,    27,    14,    56,   257,
     258,   259,   260,    18,    56,    56,    26,     1,    56,    63,
     303,    66,    -1,    -1,    -1,    -1,   274,   275,   245,     0,
       1,    -1,     3,     4,     5,     6,     7,    -1,     9,     1,
      11,    -1,   290,   292,    15,    16,    17,    -1,    19,    20,
      -1,    22,   301,    24,    -1,    -1,    -1,    -1,   307,    43,
      44,   309,     1,   311,    -1,   314,    50,    51,    52,    53,
      54,    55,    -1,    57,    58,    59,    -1,    61,    62,    63,
      64,    43,    44,    -1,     1,    -1,    -1,    -1,    50,    51,
      52,    53,    54,    55,    -1,    57,    58,    59,    -1,    61,
      62,    63,    64,    -1,    43,    44,     1,    -1,    -1,    -1,
      -1,    50,    51,    52,    53,    54,    55,    -1,    57,    58,
      59,    -1,    61,    62,    63,    64,    43,    44,     1,    -1,
      -1,    -1,    -1,    50,    51,    52,    53,    54,    55,    -1,
      57,    58,    59,    -1,    61,    62,    63,    64,    43,    44,
      -1,    -1,    -1,    -1,    -1,    50,    51,    52,    53,    54,
      55,    -1,    57,    58,    59,    -1,    61,    62,    63,    64,
      43,    44,    -1,    -1,    -1,    -1,    -1,    50,    51,    52,
      53,    54,    55,    18,    57,    58,    59,    -1,    61,    62,
      63,    64,    -1,    28,    29,    30,    31,    32,    33,    34,
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
      45,    46,    47,    48,    18,    -1,    -1,    -1,    -1,    -1,
      -1,    -1,    -1,    -1,    28,    29,    30,    31,    32,    33,
      34,    35,    36,    37,    38,    39,    40,    41,    42,    43,
      44,    45,    46,    47,    48,    18,    -1,    -1,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,    28,    29,    30,    31,    32,
      33,    34,    35,    36,    37,    38,    39,    40,    41,    42,
      43,    44,    45,    46,    47,    48,    18,    -1,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,    -1,    28,    29,    30,    31,
      32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
      42,    43,    44,    45,    46,    47,    48,    18,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    28,    29,    30,
      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
      41,    42,    43,    44,    45,    46,    47,    48,    28,    29,
      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
      40,    41,    42,    43,    44,    45,    46,    47,    48,    -1,
      21,    -1,    -1,    -1,    -1,    -1,    56,    28,    29,    30,
      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
      41,    42,    43,    44,    45,    46,    47,    48,     0,     1,
      -1,     3,     4,     5,     6,     7,    -1,     9,    -1,    11,
      -1,    -1,    -1,    15,    16,    17,    -1,    19,    20,    -1,
      22,     1,    24,     3,     4,     5,     6,     7,    -1,     9,
      -1,    11,    12,    13,    14,    15,    16,    17,    -1,    19,
      20,    -1,    22,     1,    24,     3,     4,     5,     6,     7,
      -1,     9,    -1,    11,    12,    13,    14,    15,    16,    17,
      -1,    19,    20,    -1,    22,     1,    24,     3,     4,     5,
       6,     7,    -1,     9,    -1,    11,    12,    13,    14,    15,
      16,    17,    -1,    19,    20,    -1,    22,     1,    24,     3,
       4,     5,     6,     7,    -1,     9,    -1,    11,    12,    13,
      14,    15,    16,    17,    -1,    19,    20,    -1,    22,     1,
      24,     3,     4,     5,     6,     7,     8,     9,    -1,    11,
      -1,    -1,    -1,    15,    16,    17,    -1,    19,    20,    -1,
      22,     1,    24,     3,     4,     5,     6,     7,     8,     9,
      -1,    11,    -1,    -1,    -1,    15,    16,    17,    -1,    19,
      20,    -1,    22,     1,    24,     3,     4,     5,     6,     7,
      -1,     9,    10,    11,    -1,    -1,    -1,    15,    16,    17,
      -1,    19,    20,    -1,    22,     1,    24,     3,     4,     5,
       6,     7,    -1,     9,    10,    11,    -1,    -1,    -1,    15,
      16,    17,    -1,    19,    20,    -1,    22,     1,    24,     3,
       4,     5,     6,     7,    -1,     9,    -1,    11,    -1,    -1,
      -1,    15,    16,    17,    -1,    19,    20,    -1,    22,    23,
      24,     1,    -1,     3,     4,     5,     6,     7,    -1,     9,
      -1,    11,    -1,    -1,    -1,    15,    16,    17,    -1,    19,
      20,    -1,    22,    23,    24,     1,    -1,     3,     4,     5,
       6,     7,    -1,     9,    -1,    11,    -1,    -1,    14,    15,
      16,    17,    -1,    19,    20,    -1,    22,    26,    24,    28,
      29,    30,    31,    32,    33,    34,    35,    36,    37,    38,
      39,    40,    41,    42,    43,    44,    45,    46,    47,    48,
      26,    -1,    28,    29,    30,    31,    32,    33,    34,    35,
      36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
      46,    47,    48,    27,    28,    29,    30,    31,    32,    33,
      34,    35,    36,    37,    38,    39,    40,    41,    42,    43,
      44,    45,    46,    47,    48,    43,    44,    -1,    -1,    -1,
      -1,    -1,    50,    51,    52,    53,    54,    55,    -1,    57,
      58,    59,    -1,    61,    62,    63,    64,    28,    29,    30,
      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
      41,    42,    43,    44,    45,    46,    47,    48,    29,    30,
      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
      41,    42,    43,    44,    45,    46,    47,    48,    30,    31,
      32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
      42,    43,    44,    45,    46,    47,    48,    32,    33,    34,
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
      45,    46,    47,    48,    33,    34,    35,    36,    37,    38,
      39,    40,    41,    42,    43,    44,    45,    46,    47,    48,
      34,    35,    36,    37,    38,    39,    40,    41,    42,    43,
      44,    45,    46,    47,    48
};

/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
   symbol of state STATE-NUM.  */
static const yytype_uint8 yystos[] =
{
       0,     1,    66,    67,     0,     1,     3,     4,     5,     6,
       7,     9,    11,    15,    16,    17,    19,    20,    22,    24,
      68,    69,    70,    71,    75,    77,    82,    87,    91,   109,
     112,   114,   119,    81,    86,    98,    99,   100,   118,     1,
      61,    72,    74,    72,     1,    74,     1,    74,     1,    60,
      61,   132,   133,     1,    43,    44,    50,    51,    52,    53,
      54,    55,    57,    58,    59,    61,    62,    63,    64,   120,
     129,   130,   134,   145,   147,   149,     1,    59,   131,     1,
     120,     1,     1,    61,   120,   132,     1,    61,   128,     1,
      62,   132,     8,    10,    12,    13,    14,    23,    73,    25,
      18,    76,    18,    79,    80,    18,    84,    85,    61,   133,
      18,    94,    97,   125,   126,   120,   120,    55,    55,    55,
       1,   120,   120,   128,   132,    55,   130,    18,    28,    29,
      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
      40,    41,    42,    43,    44,    45,    46,    47,    48,    89,
      90,   132,   110,    18,    18,   111,    21,    21,   113,    21,
     116,   117,    18,    18,    72,    72,     1,    72,    72,    72,
      18,    62,    18,    18,     8,    78,    18,    10,   133,    83,
      18,    14,   120,   120,     1,   120,     1,   132,     1,   132,
     127,    56,     1,   120,   151,    92,   123,   121,   122,   120,
     120,   120,   120,   120,   120,   120,   120,   120,   120,   120,
     120,   120,   120,   120,   120,   120,   120,    25,    18,    25,
      18,    21,    21,    18,    23,   115,    18,    74,    67,    72,
      67,    67,    72,    67,    95,    72,   136,   137,    26,   146,
      56,   148,    56,    56,   150,    26,    56,    67,   120,   120,
     120,   120,     1,   120,    67,    72,    67,     8,     8,    10,
      10,    67,    26,    56,   135,    56,    56,    56,   151,    93,
      27,    18,    88,    18,    23,    23,    72,    72,    72,    72,
      96,    43,    44,    48,   129,   138,   143,   144,   138,    12,
      13,   101,   124,    18,    72,    72,   101,    63,    64,    63,
      64,    27,    56,    26,    27,    56,     1,   103,    72,    14,
     120,    14,   120,   144,   139,   106,   120,   102,    72,    72,
     120,    18,    18,    67,   140,   107,   104,    26,   141,    67,
      67,   142,   108,   105,   138,   101,   101
};

#define yyerrok		(yyerrstatus = 0)
#define yyclearin	(yychar = YYEMPTY)
#define YYEMPTY		(-2)
#define YYEOF		0

#define YYACCEPT	goto yyacceptlab
#define YYABORT		goto yyabortlab
#define YYERROR		goto yyerrorlab


/* Like YYERROR except do call yyerror.  This remains here temporarily
   to ease the transition to the new meaning of YYERROR, for GCC.
   Once GCC version 2 has supplanted version 1, this can go.  */

#define YYFAIL		goto yyerrlab

#define YYRECOVERING()  (!!yyerrstatus)

#define YYBACKUP(Token, Value)					\
do								\
  if (yychar == YYEMPTY && yylen == 1)				\
    {								\
      yychar = (Token);						\
      yylval = (Value);						\
      yytoken = YYTRANSLATE (yychar);				\
      YYPOPSTACK (1);						\
      goto yybackup;						\
    }								\
  else								\
    {								\
      yyerror (YY_("syntax error: cannot back up")); \
      YYERROR;							\
    }								\
while (YYID (0))


#define YYTERROR	1
#define YYERRCODE	256


/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
   If N is 0, then set CURRENT to the empty location which ends
   the previous symbol: RHS[0] (always defined).  */

#define YYRHSLOC(Rhs, K) ((Rhs)[K])
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N)				\
    do									\
      if (YYID (N))                                                    \
	{								\
	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
	}								\
      else								\
	{								\
	  (Current).first_line   = (Current).last_line   =		\
	    YYRHSLOC (Rhs, 0).last_line;				\
	  (Current).first_column = (Current).last_column =		\
	    YYRHSLOC (Rhs, 0).last_column;				\
	}								\
    while (YYID (0))
#endif


/* YY_LOCATION_PRINT -- Print the location on the stream.
   This macro was not mandated originally: define only if we know
   we won't break user code: when these are the locations we know.  */

#ifndef YY_LOCATION_PRINT
# if YYLTYPE_IS_TRIVIAL
#  define YY_LOCATION_PRINT(File, Loc)			\
     fprintf (File, "%d.%d-%d.%d",			\
	      (Loc).first_line, (Loc).first_column,	\
	      (Loc).last_line,  (Loc).last_column)
# else
#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif
#endif


/* YYLEX -- calling `yylex' with the right arguments.  */

#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval)
#endif

/* Enable debugging if requested.  */
#if YYDEBUG

# ifndef YYFPRINTF
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
#  define YYFPRINTF fprintf
# endif

# define YYDPRINTF(Args)			\
do {						\
  if (yydebug)					\
    YYFPRINTF Args;				\
} while (YYID (0))

# define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
do {									  \
  if (yydebug)								  \
    {									  \
      YYFPRINTF (stderr, "%s ", Title);					  \
      yy_symbol_print (stderr,						  \
		  Type, Value); \
      YYFPRINTF (stderr, "\n");						  \
    }									  \
} while (YYID (0))


/*--------------------------------.
| Print this symbol on YYOUTPUT.  |
`--------------------------------*/

/*ARGSUSED*/
#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
#else
static void
yy_symbol_value_print (yyoutput, yytype, yyvaluep)
    FILE *yyoutput;
    int yytype;
    YYSTYPE const * const yyvaluep;
#endif
{
  if (!yyvaluep)
    return;
# ifdef YYPRINT
  if (yytype < YYNTOKENS)
    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
# else
  YYUSE (yyoutput);
# endif
  switch (yytype)
    {
      default:
	break;
    }
}


/*--------------------------------.
| Print this symbol on YYOUTPUT.  |
`--------------------------------*/

#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
#else
static void
yy_symbol_print (yyoutput, yytype, yyvaluep)
    FILE *yyoutput;
    int yytype;
    YYSTYPE const * const yyvaluep;
#endif
{
  if (yytype < YYNTOKENS)
    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  else
    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);

  yy_symbol_value_print (yyoutput, yytype, yyvaluep);
  YYFPRINTF (yyoutput, ")");
}

/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included).                                                   |
`------------------------------------------------------------------*/

#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static void
yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
#else
static void
yy_stack_print (bottom, top)
    yytype_int16 *bottom;
    yytype_int16 *top;
#endif
{
  YYFPRINTF (stderr, "Stack now");
  for (; bottom <= top; ++bottom)
    YYFPRINTF (stderr, " %d", *bottom);
  YYFPRINTF (stderr, "\n");
}

# define YY_STACK_PRINT(Bottom, Top)				\
do {								\
  if (yydebug)							\
    yy_stack_print ((Bottom), (Top));				\
} while (YYID (0))


/*------------------------------------------------.
| Report that the YYRULE is going to be reduced.  |
`------------------------------------------------*/

#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static void
yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
#else
static void
yy_reduce_print (yyvsp, yyrule)
    YYSTYPE *yyvsp;
    int yyrule;
#endif
{
  int yynrhs = yyr2[yyrule];
  int yyi;
  unsigned long int yylno = yyrline[yyrule];
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
	     yyrule - 1, yylno);
  /* The symbols being reduced.  */
  for (yyi = 0; yyi < yynrhs; yyi++)
    {
      fprintf (stderr, "   $%d = ", yyi + 1);
      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
		       &(yyvsp[(yyi + 1) - (yynrhs)])
		       		       );
      fprintf (stderr, "\n");
    }
}

# define YY_REDUCE_PRINT(Rule)		\
do {					\
  if (yydebug)				\
    yy_reduce_print (yyvsp, Rule); \
} while (YYID (0))

/* Nonzero means print parse trace.  It is left uninitialized so that
   multiple parsers can coexist.  */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */


/* YYINITDEPTH -- initial size of the parser's stacks.  */
#ifndef	YYINITDEPTH
# define YYINITDEPTH 200
#endif

/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
   if the built-in stack extension method is used).

   Do not make this value too large; the results are undefined if
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
   evaluated with infinite-precision integer arithmetic.  */

#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif



#if YYERROR_VERBOSE

# ifndef yystrlen
#  if defined __GLIBC__ && defined _STRING_H
#   define yystrlen strlen
#  else
/* Return the length of YYSTR.  */
#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static YYSIZE_T
yystrlen (const char *yystr)
#else
static YYSIZE_T
yystrlen (yystr)
    const char *yystr;
#endif
{
  YYSIZE_T yylen;
  for (yylen = 0; yystr[yylen]; yylen++)
    continue;
  return yylen;
}
#  endif
# endif

# ifndef yystpcpy
#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
#   define yystpcpy stpcpy
#  else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
   YYDEST.  */
#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static char *
yystpcpy (char *yydest, const char *yysrc)
#else
static char *
yystpcpy (yydest, yysrc)
    char *yydest;
    const char *yysrc;
#endif
{
  char *yyd = yydest;
  const char *yys = yysrc;

  while ((*yyd++ = *yys++) != '\0')
    continue;

  return yyd - 1;
}
#  endif
# endif

# ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
   quotes and backslashes, so that it's suitable for yyerror.  The
   heuristic is that double-quoting is unnecessary unless the string
   contains an apostrophe, a comma, or backslash (other than
   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
   null, do not copy; instead, return the length of what the result
   would have been.  */
static YYSIZE_T
yytnamerr (char *yyres, const char *yystr)
{
  if (*yystr == '"')
    {
      YYSIZE_T yyn = 0;
      char const *yyp = yystr;

      for (;;)
	switch (*++yyp)
	  {
	  case '\'':
	  case ',':
	    goto do_not_strip_quotes;

	  case '\\':
	    if (*++yyp != '\\')
	      goto do_not_strip_quotes;
	    /* Fall through.  */
	  default:
	    if (yyres)
	      yyres[yyn] = *yyp;
	    yyn++;
	    break;

	  case '"':
	    if (yyres)
	      yyres[yyn] = '\0';
	    return yyn;
	  }
    do_not_strip_quotes: ;
    }

  if (! yyres)
    return yystrlen (yystr);

  return yystpcpy (yyres, yystr) - yyres;
}
# endif

/* Copy into YYRESULT an error message about the unexpected token
   YYCHAR while in state YYSTATE.  Return the number of bytes copied,
   including the terminating null byte.  If YYRESULT is null, do not
   copy anything; just return the number of bytes that would be
   copied.  As a special case, return 0 if an ordinary "syntax error"
   message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
   size calculation.  */
static YYSIZE_T
yysyntax_error (char *yyresult, int yystate, int yychar)
{
  int yyn = yypact[yystate];

  if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
    return 0;
  else
    {
      int yytype = YYTRANSLATE (yychar);
      YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
      YYSIZE_T yysize = yysize0;
      YYSIZE_T yysize1;
      int yysize_overflow = 0;
      enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
      char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
      int yyx;

# if 0
      /* This is so xgettext sees the translatable formats that are
	 constructed on the fly.  */
      YY_("syntax error, unexpected %s");
      YY_("syntax error, unexpected %s, expecting %s");
      YY_("syntax error, unexpected %s, expecting %s or %s");
      YY_("syntax error, unexpected %s, expecting %s or %s or %s");
      YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
# endif
      char *yyfmt;
      char const *yyf;
      static char const yyunexpected[] = "syntax error, unexpected %s";
      static char const yyexpecting[] = ", expecting %s";
      static char const yyor[] = " or %s";
      char yyformat[sizeof yyunexpected
		    + sizeof yyexpecting - 1
		    + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
		       * (sizeof yyor - 1))];
      char const *yyprefix = yyexpecting;

      /* Start YYX at -YYN if negative to avoid negative indexes in
	 YYCHECK.  */
      int yyxbegin = yyn < 0 ? -yyn : 0;

      /* Stay within bounds of both yycheck and yytname.  */
      int yychecklim = YYLAST - yyn + 1;
      int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
      int yycount = 1;

      yyarg[0] = yytname[yytype];
      yyfmt = yystpcpy (yyformat, yyunexpected);

      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
	if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
	  {
	    if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
	      {
		yycount = 1;
		yysize = yysize0;
		yyformat[sizeof yyunexpected - 1] = '\0';
		break;
	      }
	    yyarg[yycount++] = yytname[yyx];
	    yysize1 = yysize + yytnamerr (0, yytname[yyx]);
	    yysize_overflow |= (yysize1 < yysize);
	    yysize = yysize1;
	    yyfmt = yystpcpy (yyfmt, yyprefix);
	    yyprefix = yyor;
	  }

      yyf = YY_(yyformat);
      yysize1 = yysize + yystrlen (yyf);
      yysize_overflow |= (yysize1 < yysize);
      yysize = yysize1;

      if (yysize_overflow)
	return YYSIZE_MAXIMUM;

      if (yyresult)
	{
	  /* Avoid sprintf, as that infringes on the user's name space.
	     Don't have undefined behavior even if the translation
	     produced a string with the wrong number of "%s"s.  */
	  char *yyp = yyresult;
	  int yyi = 0;
	  while ((*yyp = *yyf) != '\0')
	    {
	      if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
		{
		  yyp += yytnamerr (yyp, yyarg[yyi++]);
		  yyf += 2;
		}
	      else
		{
		  yyp++;
		  yyf++;
		}
	    }
	}
      return yysize;
    }
}
#endif /* YYERROR_VERBOSE */


/*-----------------------------------------------.
| Release the memory associated to this symbol.  |
`-----------------------------------------------*/

/*ARGSUSED*/
#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
#else
static void
yydestruct (yymsg, yytype, yyvaluep)
    const char *yymsg;
    int yytype;
    YYSTYPE *yyvaluep;
#endif
{
  YYUSE (yyvaluep);

  if (!yymsg)
    yymsg = "Deleting";
  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);

  switch (yytype)
    {

      default:
	break;
    }
}


/* Prevent warnings from -Wmissing-prototypes.  */

#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */






/*----------.
| yyparse.  |
`----------*/

#ifdef YYPARSE_PARAM
#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
int
yyparse (void *YYPARSE_PARAM)
#else
int
yyparse (YYPARSE_PARAM)
    void *YYPARSE_PARAM;
#endif
#else /* ! YYPARSE_PARAM */
#if (defined __STDC__ || defined __C99__FUNC__ \
     || defined __cplusplus || defined _MSC_VER)
int
yyparse (void)
#else
int
yyparse ()

#endif
#endif
{
  /* The look-ahead symbol.  */
int yychar;

/* The semantic value of the look-ahead symbol.  */
YYSTYPE yylval;

/* Number of syntax errors so far.  */
int yynerrs;

  int yystate;
  int yyn;
  int yyresult;
  /* Number of tokens to shift before error messages enabled.  */
  int yyerrstatus;
  /* Look-ahead token as an internal (translated) token number.  */
  int yytoken = 0;
#if YYERROR_VERBOSE
  /* Buffer for error messages, and its allocated size.  */
  char yymsgbuf[128];
  char *yymsg = yymsgbuf;
  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif

  /* Three stacks and their tools:
     `yyss': related to states,
     `yyvs': related to semantic values,
     `yyls': related to locations.

     Refer to the stacks thru separate pointers, to allow yyoverflow
     to reallocate them elsewhere.  */

  /* The state stack.  */
  yytype_int16 yyssa[YYINITDEPTH];
  yytype_int16 *yyss = yyssa;
  yytype_int16 *yyssp;

  /* The semantic value stack.  */
  YYSTYPE yyvsa[YYINITDEPTH];
  YYSTYPE *yyvs = yyvsa;
  YYSTYPE *yyvsp;



#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))

  YYSIZE_T yystacksize = YYINITDEPTH;

  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;


  /* The number of symbols on the RHS of the reduced rule.
     Keep to zero when no symbol should be popped.  */
  int yylen = 0;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY;		/* Cause a token to be read.  */

  /* Initialize stack pointers.
     Waste one element of value and location stack
     so that they stay on the same level as the state stack.
     The wasted elements are never initialized.  */

  yyssp = yyss;
  yyvsp = yyvs;

  goto yysetstate;

/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
 yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed.  So pushing a state here evens the stacks.  */
  yyssp++;

 yysetstate:
  *yyssp = yystate;

  if (yyss + yystacksize - 1 <= yyssp)
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYSIZE_T yysize = yyssp - yyss + 1;

#ifdef yyoverflow
      {
	/* Give user a chance to reallocate the stack.  Use copies of
	   these so that the &'s don't force the real ones into
	   memory.  */
	YYSTYPE *yyvs1 = yyvs;
	yytype_int16 *yyss1 = yyss;


	/* Each stack pointer address is followed by the size of the
	   data in use in that stack, in bytes.  This used to be a
	   conditional around just the two extra args, but that might
	   be undefined if yyoverflow is a macro.  */
	yyoverflow (YY_("memory exhausted"),
		    &yyss1, yysize * sizeof (*yyssp),
		    &yyvs1, yysize * sizeof (*yyvsp),

		    &yystacksize);

	yyss = yyss1;
	yyvs = yyvs1;
      }
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
      goto yyexhaustedlab;
# else
      /* Extend the stack our own way.  */
      if (YYMAXDEPTH <= yystacksize)
	goto yyexhaustedlab;
      yystacksize *= 2;
      if (YYMAXDEPTH < yystacksize)
	yystacksize = YYMAXDEPTH;

      {
	yytype_int16 *yyss1 = yyss;
	union yyalloc *yyptr =
	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
	if (! yyptr)
	  goto yyexhaustedlab;
	YYSTACK_RELOCATE (yyss);
	YYSTACK_RELOCATE (yyvs);

#  undef YYSTACK_RELOCATE
	if (yyss1 != yyssa)
	  YYSTACK_FREE (yyss1);
      }
# endif
#endif /* no yyoverflow */

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;


      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
		  (unsigned long int) yystacksize));

      if (yyss + yystacksize - 1 <= yyssp)
	YYABORT;
    }

  YYDPRINTF ((stderr, "Entering state %d\n", yystate));

  goto yybackup;

/*-----------.
| yybackup.  |
`-----------*/
yybackup:

  /* Do appropriate processing given the current state.  Read a
     look-ahead token if we need one and don't already have one.  */

  /* First try to decide what to do without reference to look-ahead token.  */
  yyn = yypact[yystate];
  if (yyn == YYPACT_NINF)
    goto yydefault;

  /* Not known => get a look-ahead token if don't already have one.  */

  /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token: "));
      yychar = YYLEX;
    }

  if (yychar <= YYEOF)
    {
      yychar = yytoken = YYEOF;
      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else
    {
      yytoken = YYTRANSLATE (yychar);
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    }

  /* If the proper action on seeing token YYTOKEN is to reduce or to
     detect an error, take that action.  */
  yyn += yytoken;
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (yyn == 0 || yyn == YYTABLE_NINF)
	goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }

  if (yyn == YYFINAL)
    YYACCEPT;

  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  /* Shift the look-ahead token.  */
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);

  /* Discard the shifted token unless it is eof.  */
  if (yychar != YYEOF)
    yychar = YYEMPTY;

  yystate = yyn;
  *++yyvsp = yylval;

  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- Do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     `$$ = $1'.

     Otherwise, the following line sets YYVAL to garbage.
     This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
        case 2:
#line 447 "tengsyntax.yy"
    {
            CODE(HALT); //end of template
        }
    break;

  case 3:
#line 453 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(FATAL, CONTEXT->position, "Big, fatal or "
                        "unhandled parse error in template");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
            CONTEXT->program->erase(CONTEXT->program->begin(),
                    CONTEXT->program->end()); //discard program
            CODE(HALT); //end of program
        }
    break;

  case 4:
#line 470 "tengsyntax.yy"
    {
            CODE_VAL(VAL, (yyvsp[(2) - (2)]).val); //static text
            tengCode_generatePrint(CONTEXT);
        }
    break;

  case 19:
#line 497 "tengsyntax.yy"
    {
            ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Unknown <?teng"
                    + (yyvsp[(1) - (3)]).val.stringValue + "?> directive");
        }
    break;

  case 20:
#line 506 "tengsyntax.yy"
    {
            CODE(DEBUGING); //print debug info
        }
    break;

  case 21:
#line 514 "tengsyntax.yy"
    {
            CODE(BYTECODE); //print disassembled bytecode
        }
    break;

  case 22:
#line 522 "tengsyntax.yy"
    {
            if ((yyvsp[(1) - (2)]).opt.size() > 0)
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Teng directive "
                        "does not accept any option(s)");
        }
    break;

  case 23:
#line 530 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, CONTEXT->position, "Syntax error "
                        "inside <?teng ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 25:
#line 544 "tengsyntax.yy"
    {
            (yyval).opt = (yyvsp[(4) - (4)]).opt; //get all nested options
            (yyval).opt.insert(make_pair((yyvsp[(1) - (4)]).val.stringValue, (yyvsp[(3) - (4)]).val.stringValue));
            (yyval).pos = (yyvsp[(1) - (4)]).pos; //propagate start of options position
        }
    break;

  case 26:
#line 550 "tengsyntax.yy"
    {
            (yyval).opt.erase((yyval).opt.begin(), (yyval).opt.end()); //clear residuals
        }
    break;

  case 27:
#line 558 "tengsyntax.yy"
    {
            // file may be included only at the end of teng directive,
            // because of flex-generated lexical analyzer is not reentrant.
            LeftValue_t::OptionList_t::const_iterator i = (yyvsp[(2) - (3)]).opt.find("file");
            if (i == (yyvsp[(2) - (3)]).opt.end()) {
                ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Cannot include a file; "
                        "option 'file' is not specified");
            } else if (CONTEXT->lex1.size() >=
                       CONTEXT->paramDictionary->getMaxIncludeDepth()) {
                ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Cannot include a file; template "
                        "nesting level is too deep");
            } else {
                // glue filename
                string fname = i->second;
                if (!CONTEXT->root.empty() && !fname.empty() && fname[0] != '/')
                    fname = CONTEXT->root + "/" + fname;
                // create new level #1 lex analyzer with file input
                CONTEXT->lex1.push(new Lex1_t(fname,
                        CONTEXT->lex1.top()->getPosition(),
                        CONTEXT->program->getErrors())); //new lex1
                // lex2 state should be 0 now (or after a while)
                tengLex2_finish();
                CONTEXT->lex2 = 0; //for sure
                // append source list
                CONTEXT->sourceIndex.push( //remember source index
                        CONTEXT->program->addSource(fname,
                        CONTEXT->lex1.top()->getPosition()));
            }
        }
    break;

  case 28:
#line 590 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid <?teng "
                        "include ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 30:
#line 604 "tengsyntax.yy"
    {
            // get chosen formating type
            LeftValue_t::OptionList_t::const_iterator i = (yyvsp[(2) - (3)]).opt.find("space");
            if (i == (yyvsp[(2) - (3)]).opt.end() || i->second.length() == 0) {
                ERR(ERROR, (yyvsp[(1) - (3)]).pos,"Formatting block has no effect; "
                        "option 'space' is not specified or is empty");
            } else {
                // reset val
                (yyval).val = ParserValue_t();
                (yyval).val.integerValue = -1;
                // check space option
                if (i->second == "nowhite") {
                    (yyval).val.integerValue = Formatter_t::MODE_NOWHITE;
                } else if (i->second == "onespace") {
                    (yyval).val.integerValue = Formatter_t::MODE_ONESPACE;
                } else if (i->second == "striplines") {
                    (yyval).val.integerValue = Formatter_t::MODE_STRIPLINES;
                } else if (i->second == "joinlines") {
                    (yyval).val.integerValue = Formatter_t::MODE_JOINLINES;
                } else if (i->second == "nowhitelines") {
                    (yyval).val.integerValue = Formatter_t::MODE_NOWHITELINES;
                } else if (i->second == "noformat") {
                    (yyval).val.integerValue = Formatter_t::MODE_PASSWHITE;
                } else {
                    ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Unsupported value '" + i->second
                            + "' of 'space' formatting option");
                }
                // if not err, generate code
                if ((yyval).val.integerValue >= 0)
                    CODE_VAL(FORM, (yyval).val);
            }
        }
    break;

  case 31:
#line 637 "tengsyntax.yy"
    {
            // if was not error no block start
            if ((yyvsp[(4) - (7)]).val.integerValue >= 0)
                CODE(ENDFORM); //generate code
            // do not optimize (join) print-vals across current prog end-addr
            CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
        }
    break;

  case 32:
#line 647 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid <?teng format ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 34:
#line 656 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Syntax error in teng format block; "
                        "discarding block content");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 35:
#line 665 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (5)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 36:
#line 670 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                // If EOF, do not print this message
                printUnexpectedElement(CONTEXT, yychar, yylval);
                if (yychar) // I don't know why, but when unexpected EOF
                            // occurs, this error handler is called
                    ERR(ERROR, CONTEXT->position,
                        "Misplaced <?teng endformat?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 37:
#line 682 "tengsyntax.yy"
    {
            // discard program from point the LEX_ENDFORMAT was read
            // (destroy HALT instruction created by reduction start->template)
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(3) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 38:
#line 693 "tengsyntax.yy"
    {
            // save actual prog size/addr
            (yyval).prgsize = CONTEXT->program->size();
            // clear val and copy variable identifier
            (yyval).val = ParserValue_t(); //clear
            (yyval).id = (yyvsp[(2) - (3)]).id;
            (yyval).val.stringValue = (yyvsp[(2) - (3)]).val.stringValue;

            Identifier_t id;
            if (CONTEXT->pushFragment((yyvsp[(2) - (3)]).pos, (yyval).id, (yyval).val.stringValue, id)) {
                // generate code
                CODE_VAL(FRAG, (yyval).val);
                // set identifier
                CONTEXT->program->back().identifier = id;
            } else {
                // error in fragment, erase identifier to mark error
                (yyval).id.clear();
            }
        }
    break;

  case 39:
#line 713 "tengsyntax.yy"
    {
            // pop previous fragment or remove invalid code
            if ((yyvsp[(4) - (7)]).id.empty()) CONTEXT->cropCode((yyvsp[(4) - (7)]).prgsize);
            else {
                // generate code for fragment end
                CODE(ENDFRAG);
                // pop frame
                CONTEXT->popFragment((yyvsp[(4) - (7)]).prgsize);
            }
        }
    break;

  case 40:
#line 726 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid <?teng frag ...?> directive; "
                        "discarding fragment block content");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 41:
#line 735 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (7)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 42:
#line 740 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Syntax error in teng fragment block; "
                        "discarding block content");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 43:
#line 749 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (5)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 44:
#line 754 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, CONTEXT->position,
                        "Misplaced <?teng endfrag?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 45:
#line 763 "tengsyntax.yy"
    {
            // discard program from point the LEX_ENDFRAGMENT was read
            // (destroy HALT instruction created by reduction start->template)
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(3) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 46:
#line 775 "tengsyntax.yy"
    {
            // clear val and copy variable identifier
            (yyval).val = ParserValue_t(); //clear
            (yyval).id = (yyvsp[(3) - (6)]).id;
            (yyval).val.stringValue = (yyvsp[(3) - (6)]).val.stringValue;

            // error indicator
            bool found = false;

            if ((yyval).id.size() == 0) {
                // bad variable identifier
                ERR(ERROR, (yyvsp[(3) - (6)]).pos, "Invalid variable identifier; "
                        "variable will not be set");
            } else {
                Identifier_t id;
                if (CONTEXT->
                    findFragmentForVariable((yyval).pos, (yyval).id,
                                            (yyval).val.stringValue, id)) {
                    // fully qualified variable identifier is in
                    // $$.val.stringValue
                    CODE_VAL(SET, (yyval).val);
                    // set identifier
                    CONTEXT->program->back().identifier = id;
                    found = true;
                }
            }
            if (!found) {
                // variable not found => destroy program for expression
                CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (6)]).prgsize,
                                        CONTEXT->program->end());
            }
        }
    break;

  case 47:
#line 811 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (5)]).pos, "Invalid expression in <?teng set ...?> "
                        "directive; variable '" +(yyvsp[(3) - (5)]).val.stringValue
                        + "' will not be set");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 48:
#line 821 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (7)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 49:
#line 826 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid variable identifier in "
                        "<?teng set ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 50:
#line 835 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (6)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 51:
#line 840 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid <?teng set ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 52:
#line 848 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 53:
#line 857 "tengsyntax.yy"
    {
            // here is $4
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
            CODE(JMPIFNOT); //if not true, jump to next case
        }
    break;

  case 54:
#line 863 "tengsyntax.yy"
    {
            // here is $6
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
        }
    break;

  case 55:
#line 868 "tengsyntax.yy"
    {
            // calculate jump offset
            // add +1 for end-jump if some else(if) section was generated
            (*CONTEXT->program)[(yyvsp[(4) - (9)]).prgsize].value.integerValue =
                    (yyvsp[(6) - (9)]).prgsize - (yyvsp[(4) - (9)]).prgsize - 1
                    + ((yyvsp[(6) - (9)]).prgsize != CONTEXT->program->size());
            // update all end-jumps with proper address
            LeftValue_t::AddressList_t::const_iterator i;
            for (i = (yyvsp[(7) - (9)]).addr.begin(); i != (yyvsp[(7) - (9)]).addr.end(); ++i) {
                (*CONTEXT->program)[*i].value.integerValue =
                        CONTEXT->program->size() - *i - 1;
            }
            // do not optimize (join) print-vals across current prog end-addr
            CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
        }
    break;

  case 56:
#line 886 "tengsyntax.yy"
    {
            // if expression error, behave like the expression is true
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Error in condition expression "
                        "in <?teng if ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 57:
#line 896 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard expression program
        }
    break;

  case 58:
#line 901 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
        }
    break;

  case 59:
#line 905 "tengsyntax.yy"
    {
        	// delete all else(if) code for the faily if expression
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(7) - (10)]).prgsize,
                    CONTEXT->program->end()); //discard further else-parts
        }
    break;

  case 60:
#line 911 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Syntax error in teng conditional "
                        "block; discarding block content");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 61:
#line 920 "tengsyntax.yy"
    {
        	// drop whole if section code
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (5)]).prgsize,
                    CONTEXT->program->end()); //discard else-parts of program
        }
    break;

  case 62:
#line 926 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, CONTEXT->position, "Misplaced "
                        "<?teng elseif ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 63:
#line 935 "tengsyntax.yy"
    {
            // discard program from point the LEX_ELSEIF was read
            // (destroy HALT instruction created by reduction start->template)
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(3) - (5)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 64:
#line 942 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, CONTEXT->position,
                        "Misplaced <?teng else?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 65:
#line 951 "tengsyntax.yy"
    {
            // discard program from point the LEX_ELSE was read
            // (destroy HALT instruction created by reduction start->template)
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(3) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 66:
#line 958 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, CONTEXT->position,
                        "Misplaced <?teng endif?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 67:
#line 967 "tengsyntax.yy"
    {
            // discard program from point the LEX_ENDIF was read
            // (destroy HALT instruction created by reduction start->template)
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(3) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 68:
#line 978 "tengsyntax.yy"
    {
            // insert previous program block end-jump
            (yyval).addr.erase((yyval).addr.begin(), (yyval).addr.end()); //clear
            (yyval).addr.push_back(CONTEXT->program->size()); //save end-jump addr
            CODE(JMP); //previous was true, skip else section
        }
    break;

  case 69:
#line 985 "tengsyntax.yy"
    {
            (yyval).addr = (yyvsp[(3) - (4)]).addr; //preserve end-jump info
        }
    break;

  case 70:
#line 989 "tengsyntax.yy"
    {
            // insert end jump
            (yyval).prgsize = CONTEXT->program->size(); //end-jump addr
            CODE(JMP); //previous was true, skip future elseif and else sections
        }
    break;

  case 71:
#line 995 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
            CODE(JMPIFNOT); //if not true, jump to the next case
        }
    break;

  case 72:
#line 1000 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
        }
    break;

  case 73:
#line 1004 "tengsyntax.yy"
    {
            // calculate jump offset
            // add +1 for end-jump if some else(if) section was generated
            (*CONTEXT->program)[(yyvsp[(5) - (8)]).prgsize].value.integerValue =
                    (yyvsp[(7) - (8)]).prgsize - (yyvsp[(5) - (8)]).prgsize - 1
                    + ((yyvsp[(7) - (8)]).prgsize != CONTEXT->program->size());
            // preserve end-jumps info
            (yyval).addr = (yyvsp[(8) - (8)]).addr;
            (yyval).addr.push_back((yyvsp[(2) - (8)]).prgsize);
        }
    break;

  case 74:
#line 1015 "tengsyntax.yy"
    {
            (yyval).addr.erase((yyval).addr.begin(), (yyval).addr.end()); //clear residuals
        }
    break;

  case 75:
#line 1021 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Error in condition expression "
                        "in <?teng elseif ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 76:
#line 1030 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard expression program
        }
    break;

  case 77:
#line 1035 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
        }
    break;

  case 78:
#line 1039 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(7) - (8)]).prgsize,
                    CONTEXT->program->end()); //discard further else-parts
        }
    break;

  case 79:
#line 1048 "tengsyntax.yy"
    {
            tengCode_generatePrint(CONTEXT); //print expression value
        }
    break;

  case 80:
#line 1052 "tengsyntax.yy"
    {
            tengCode_generatePrint(CONTEXT); //print expression value
        }
    break;

  case 81:
#line 1056 "tengsyntax.yy"
    {
            // generate code for variable
            codeForVariable(context, (yyval), (yyvsp[(2) - (3)]));
            // print value
            tengCode_generatePrint(CONTEXT);
        }
    break;

  case 82:
#line 1065 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid expression "
                        "in <?teng expr ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 83:
#line 1074 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
            (yyval).val.setString("undefined");
            CODE_VAL(VAL, (yyval).val); //fake value
            tengCode_generatePrint(CONTEXT); //print expression 'undef' value
        }
    break;

  case 84:
#line 1082 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid expression in ${...} statement");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 85:
#line 1090 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
            (yyval).val.setString("undefined");
            CODE_VAL(VAL, (yyval).val); //fake value
            tengCode_generatePrint(CONTEXT); //print expression 'undef' value
        }
    break;

  case 86:
#line 1102 "tengsyntax.yy"
    {
            tengCode_generatePrint(CONTEXT); //print dictionary item's value
        }
    break;

  case 87:
#line 1108 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid dictionary item "
                        "in #{...} statement");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 88:
#line 1117 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
            (yyval).val.setString("undefined");
            CODE_VAL(VAL, (yyval).val); //fake value
            tengCode_generatePrint(CONTEXT); //print 'undef' value
        }
    break;

  case 89:
#line 1129 "tengsyntax.yy"
    {
            // reset val
            (yyval).val = ParserValue_t();
            (yyval).val.integerValue = -1;

            // get content type descriptor for given type
            const ContentType_t::Descriptor_t *ct
                = ContentType_t::findContentType((yyvsp[(2) - (3)]).val.stringValue,
                                                 CONTEXT->program->getErrors(),
                                                 (yyvsp[(2) - (3)]).pos, true);

            if (ct) {
                (yyval).val.integerValue = ct->index;
                CODE_VAL(CTYPE, (yyval).val);
            }
        }
    break;

  case 90:
#line 1147 "tengsyntax.yy"
    {
            // if was not error no block start
            if ((yyvsp[(4) - (7)]).val.integerValue >= 0)
                CODE(ENDCTYPE); //generate code
            // no print-values join below following address
            CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
        }
    break;

  case 91:
#line 1157 "tengsyntax.yy"
    {
            if (!tengSyntax_lastErrorMessage.empty()) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid <?teng ctype ...?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 93:
#line 1166 "tengsyntax.yy"
    {
            if (!tengSyntax_lastErrorMessage.empty()) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Syntax error in teng ctype block; "
                        "discarding block content");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 94:
#line 1175 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (5)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 95:
#line 1180 "tengsyntax.yy"
    {
            if (!tengSyntax_lastErrorMessage.empty()) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, CONTEXT->position,
                        "Misplaced <?teng endctype?> directive");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 96:
#line 1189 "tengsyntax.yy"
    {
            // discard program from point the LEX_ENDCTYP was read
            // (destroy HALT instruction created by reduction start->template)
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(3) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
        }
    break;

  case 97:
#line 1199 "tengsyntax.yy"
    {
            // get address of referenced fragment
            Identifier_t id;
            int address = CONTEXT->getFragmentAddress((yyvsp[(2) - (3)]).pos, (yyvsp[(2) - (3)]).id,
                                                      (yyvsp[(2) - (3)]).val.stringValue, id);
            if (address >= 0) {
                // set offset
                (yyvsp[(2) - (3)]).val.integerValue = address - CONTEXT->program->size();

                // generate instruction
                CODE_VAL(REPEATFRAG, (yyvsp[(2) - (3)]).val);

                // set identifier
                CONTEXT->program->back().identifier = id;

                // do not optimize (join) print-vals across current
                // prog end-addr
                CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
            }
        }
    break;

  case 98:
#line 1223 "tengsyntax.yy"
    {
            (yyval).prgsize = (yyvsp[(2) - (3)]).prgsize; //start of expr prog
        }
    break;

  case 99:
#line 1227 "tengsyntax.yy"
    {
            CODE(NUMEQ);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 100:
#line 1233 "tengsyntax.yy"
    {
            CODE(NUMEQ);
            CODE(NOT);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 101:
#line 1240 "tengsyntax.yy"
    {
            CODE(NUMGE);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 102:
#line 1246 "tengsyntax.yy"
    {
            CODE(NUMGT);
            CODE(NOT);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 103:
#line 1253 "tengsyntax.yy"
    {
            CODE(NUMGT);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 104:
#line 1259 "tengsyntax.yy"
    {
            CODE(NUMGE);
            CODE(NOT);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 105:
#line 1266 "tengsyntax.yy"
    {
            CODE(STREQ);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 106:
#line 1272 "tengsyntax.yy"
    {
            CODE(STREQ);
            CODE(NOT);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 107:
#line 1279 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual prog size
            CODE(OR); //generate infix code
        }
    break;

  case 108:
#line 1284 "tengsyntax.yy"
    {
            // calc and update jump offset
            (*CONTEXT->program)[(yyvsp[(3) - (4)]).prgsize].value.integerValue =
                    CONTEXT->program->size() - (yyvsp[(3) - (4)]).prgsize - 1;
            // try to optimalize
            (yyval).prgsize = (yyvsp[(1) - (4)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
            // do not optimize (join) print-vals across current prog end-addr
            CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
        }
    break;

  case 109:
#line 1295 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual prog size
            CODE(AND); //generate infix code
        }
    break;

  case 110:
#line 1300 "tengsyntax.yy"
    {
            // calc and update jump offset
            (*CONTEXT->program)[(yyvsp[(3) - (4)]).prgsize].value.integerValue =
                    CONTEXT->program->size() - (yyvsp[(3) - (4)]).prgsize - 1;
            // try to optimalize
            (yyval).prgsize = (yyvsp[(1) - (4)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
            // do not optimize (join) print-vals across current prog end-addr
            CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
        }
    break;

  case 111:
#line 1311 "tengsyntax.yy"
    {
            CODE(BITOR);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 112:
#line 1317 "tengsyntax.yy"
    {
            CODE(BITXOR);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 113:
#line 1323 "tengsyntax.yy"
    {
            CODE(BITAND);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 114:
#line 1329 "tengsyntax.yy"
    {
            CODE(ADD);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 115:
#line 1335 "tengsyntax.yy"
    {
            CODE(SUB);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 116:
#line 1341 "tengsyntax.yy"
    {
            CODE(CONCAT);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 117:
#line 1347 "tengsyntax.yy"
    {
            CODE(MUL);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 118:
#line 1353 "tengsyntax.yy"
    {
            CODE(DIV);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 119:
#line 1359 "tengsyntax.yy"
    {
            CODE(MOD);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 120:
#line 1365 "tengsyntax.yy"
    {
            CODE(REPEAT);
            (yyval).prgsize = (yyvsp[(1) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 121:
#line 1371 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
            CODE(JMPIFNOT); //jump offset stored later
        }
    break;

  case 122:
#line 1376 "tengsyntax.yy"
    {
            // correct conditional jump offset (relative addr) +1=JMP
            (*CONTEXT->program)[(yyvsp[(3) - (5)]).prgsize].value.integerValue =
                    CONTEXT->program->size() - (yyvsp[(3) - (5)]).prgsize - 1 + 1;
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
            CODE(JMP); //jump stored later
        }
    break;

  case 123:
#line 1384 "tengsyntax.yy"
    {
            // correct jump offset (relative addr)
            (*CONTEXT->program)[(yyvsp[(6) - (7)]).prgsize].value.integerValue =
                    CONTEXT->program->size() - (yyvsp[(6) - (7)]).prgsize - 1;
            // try to optimalize
            (yyval).prgsize = (yyvsp[(1) - (7)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
            // do not optimize (join) print-vals across current prog end-addr
            CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
        }
    break;

  case 124:
#line 1395 "tengsyntax.yy"
    {
            CODE(NOT);
            (yyval).prgsize = (yyvsp[(1) - (2)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 125:
#line 1401 "tengsyntax.yy"
    {
            CODE(BITNOT);
            (yyval).prgsize = (yyvsp[(1) - (2)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 126:
#line 1407 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size();
            (yyval).val.setInteger(0); //compile as (0 - expression)
            CODE_VAL(VAL, (yyval).val);
        }
    break;

  case 127:
#line 1413 "tengsyntax.yy"
    {
            CODE(SUB);
            (yyval).prgsize = (yyvsp[(2) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 128:
#line 1419 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size();
            (yyval).val.setInteger(0); //compile as (0 + expression)
            CODE_VAL(VAL, (yyval).val);
        }
    break;

  case 129:
#line 1425 "tengsyntax.yy"
    {
            CODE(ADD);
            (yyval).prgsize = (yyvsp[(2) - (3)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 130:
#line 1431 "tengsyntax.yy"
    {
            (yyval).prgsize = (yyvsp[(2) - (2)]).prgsize;
            // this compilation is always optimal
        }
    break;

  case 131:
#line 1436 "tengsyntax.yy"
    {
            CODE(DICT); //indirect dictionary lookup
            (yyval).prgsize = (yyvsp[(2) - (2)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 132:
#line 1442 "tengsyntax.yy"
    {
            // following code cannot be optimized
            (yyval).prgsize = CONTEXT->program->size(); //start of expr prog
            // generate code for variable
            codeForVariable(context, (yyval), (yyvsp[(2) - (2)]));
        }
    break;

  case 133:
#line 1449 "tengsyntax.yy"
    {
            // following code is always optimal
            (yyval).prgsize = CONTEXT->program->size(); //start of expr prog
            CODE_VAL(VAL, (yyvsp[(1) - (1)]).val);
        }
    break;

  case 134:
#line 1455 "tengsyntax.yy"
    {
            (yyval).prgsize = (yyvsp[(1) - (1)]).prgsize; //start of expr prog
        }
    break;

  case 135:
#line 1459 "tengsyntax.yy"
    {
            (yyval).prgsize = (yyvsp[(1) - (1)]).prgsize; //start of expr prog
        }
    break;

  case 136:
#line 1463 "tengsyntax.yy"
    {
            (yyval).prgsize = (yyvsp[(1) - (1)]).prgsize; //start of expr prog
        }
    break;

  case 137:
#line 1467 "tengsyntax.yy"
    {
            (yyval).prgsize = (yyvsp[(1) - (1)]).prgsize; //start of expr prog
        }
    break;

  case 138:
#line 1473 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Invalid "
                        "sub-expression (in parentheses)");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 139:
#line 1482 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (4)]).prgsize,
                    CONTEXT->program->end()); //discard program
            (yyval).prgsize = (yyvsp[(1) - (4)]).prgsize; //start of expr prog
            (yyval).val.setString("undefined");
            CODE_VAL(VAL, (yyval).val); //fake value
        }
    break;

  case 140:
#line 1494 "tengsyntax.yy"
    {
            // find item in dictionary and code it as val
            // lookup lang dict first, param dict then else use identifier
            const string *item;
            item = CONTEXT->langDictionary->lookup((yyvsp[(1) - (1)]).val.stringValue);
            if (item == 0)
                item = CONTEXT->paramDictionary->lookup((yyvsp[(1) - (1)]).val.stringValue);
            if (item == 0) {
                ERR(ERROR, (yyvsp[(1) - (1)]).pos, "Cannot find '" + (yyvsp[(1) - (1)]).val.stringValue
                        + "' dictionary item");
                item = &((yyvsp[(1) - (1)]).val.stringValue);
            }
            // generate code
            (yyval).prgsize = CONTEXT->program->size(); //start of expr prog
            (yyval).val.setString(*item);
            CODE_VAL(VAL, (yyval).val);
        }
    break;

  case 141:
#line 1516 "tengsyntax.yy"
    {
            (yyval).val = (yyvsp[(1) - (1)]).val;
        }
    break;

  case 142:
#line 1520 "tengsyntax.yy"
    {
            (yyval).val = (yyvsp[(1) - (1)]).val;
        }
    break;

  case 143:
#line 1524 "tengsyntax.yy"
    {
            (yyval).val = (yyvsp[(1) - (1)]).val;
        }
    break;

  case 144:
#line 1532 "tengsyntax.yy"
    {
            (yyval).val = (yyvsp[(1) - (1)]).val;
        }
    break;

  case 145:
#line 1536 "tengsyntax.yy"
    {
            (yyval).val = (yyvsp[(1) - (2)]).val;
            (yyval).val.stringValue += (yyvsp[(2) - (2)]).val.stringValue;
        }
    break;

  case 147:
#line 1546 "tengsyntax.yy"
    {
#if 0
            ERR(DEBUG, CONTEXT->position, "Variable identifier should "
                    "start with '$'. Leaving it out is obsolete syntax.");
#endif
        }
    break;

  case 148:
#line 1557 "tengsyntax.yy"
    {
            // variable in local fragment context
            (yyval).id = CONTEXT->fragContext.back(); //frag context
            (yyval).id.push_back((yyvsp[(1) - (1)]).val.stringValue); //name
            (yyval).pos = (yyvsp[(1) - (1)]).pos; //var position

            // rebuild identifier
            buildIdentifier((yyval));
        }
    break;

  case 149:
#line 1567 "tengsyntax.yy"
    {
            // partitialy qualified variable
            // check for special identifier '_this'
            if ((yyvsp[(1) - (2)]).val.stringValue == "_this") {
                // supply actual fragment context
                (yyval).id = CONTEXT->fragContext.back();
                // add more identifier qualifiers and ident itself
                (yyval).id.insert((yyval).id.end(), (yyvsp[(2) - (2)]).id.begin(), (yyvsp[(2) - (2)]).id.end());
            } else {
                // try to find name on fragment stack--
                // sequence of following fragment names must match
                (yyval).id.erase((yyval).id.begin(), (yyval).id.end()); //clear
                const ParserContext_t::FragmentContext_t
                        &fc = CONTEXT->fragContext.back();
                ParserContext_t::IdentifierName_t::const_reverse_iterator
                        ri;
                for (ri = fc.name.rbegin(); ri != fc.name.rend(); ++ri)
                    if (*ri == (yyvsp[(1) - (2)]).val.stringValue)
                        break; //found fragment of specified name
                // if found
                int err = 0;
                if (ri == fc.name.rend()) {
                    err = 1; //not found
                } else {
                    // check all consequenting parts of the identifier
                    // beware! method forward iterator created using base()
                    // from reverse iterator does not refer to the same
                    // element, but to the next element in forward order.
                    ParserContext_t::IdentifierName_t::const_iterator
                            i = ri.base() - 1;
                    LeftValue_t::Identifier_t::const_iterator
                            id = (yyvsp[(2) - (2)]).id.begin();
                    ++i; //skip already matching frag name
                    while (i != fc.name.end()
                            && id != (yyvsp[(2) - (2)]).id.end()
                            && id != (yyvsp[(2) - (2)]).id.end() - 1) {
                        if (*i != *id) {
                            err = 1; //mis-match
                            break;
                        }
                        ++i;
                        ++id;
                    }
                    // if overlaying identifier parts are matching
                    if (!err) {
                        (yyval).id.insert((yyval).id.begin(), fc.name.begin(), i);
                        (yyval).id.push_back(*id);
                    } else
                        err = 1; //mis-match
                }
                // handle error
                if (err) {
                    LeftValue_t::Identifier_t::const_iterator id;
                    string var = (yyvsp[(1) - (2)]).val.stringValue;
                    for (id = (yyvsp[(2) - (2)]).id.begin(); id != (yyvsp[(2) - (2)]).id.end(); ++id)
                        var += "." + *id;
                    ERR(ERROR, (yyvsp[(1) - (2)]).pos, "Variable identifier '" + var
                            + "' not found in current context");
                }
            }
            // var position
            (yyval).pos = (yyvsp[(1) - (2)]).pos;

            // create fully-qualified identifier string
            // rebuild identifier
            buildIdentifier((yyval));
        }
    break;

  case 150:
#line 1635 "tengsyntax.yy"
    {
            // fully qualified variable name
            (yyval).id = (yyvsp[(1) - (1)]).id;
            (yyval).pos = (yyvsp[(1) - (1)]).pos; //variable position

            // create fully-qualified identifier string
            // rebuild identifier
            buildIdentifier((yyval));
        }
    break;

  case 151:
#line 1649 "tengsyntax.yy"
    {
            (yyval).id.erase((yyval).id.begin(), (yyval).id.end());
            (yyval).id.push_back((yyvsp[(2) - (2)]).val.stringValue);
            (yyval).pos = (yyvsp[(1) - (2)]).pos;
        }
    break;

  case 152:
#line 1655 "tengsyntax.yy"
    {
            (yyval).id = (yyvsp[(3) - (3)]).id;
            // ignore special identifier '_this'
            // inside the variable qualification
            if (('_' == (yyvsp[(2) - (3)]).val.stringValue[0])
                && (((yyvsp[(2) - (3)]).val.stringValue == "_this")
                    || ((yyvsp[(2) - (3)]).val.stringValue == "_parent"))) {
                ERR(DEBUGING, (yyvsp[(2) - (3)]).pos, "Using the special identifier '"
                    + (yyvsp[(2) - (3)]).val.stringValue
                    + "' inside the identifier qualification is useless");
            } else {
                (yyval).id.insert((yyval).id.begin(), (yyvsp[(2) - (3)]).val.stringValue);
                (yyval).pos = (yyvsp[(1) - (3)]).pos;
            }
        }
    break;

  case 153:
#line 1675 "tengsyntax.yy"
    {
            CODE(PUSH); //store expr value on program stack
        }
    break;

  case 154:
#line 1679 "tengsyntax.yy"
    {
            // update all end-jumps with proper address
            LeftValue_t::AddressList_t::const_iterator i;
            for (i = (yyvsp[(6) - (7)]).addr.begin(); i != (yyvsp[(6) - (7)]).addr.end(); ++i) {
                (*CONTEXT->program)[*i].value.integerValue =
                        CONTEXT->program->size() - *i - 1;
            }
            // remove previously pushed value
            CODE(POP);
            // try to optimize
            (yyval).prgsize = (yyvsp[(1) - (7)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
            // do not optimize (join) print-vals across current prog end-addr
            CONTEXT->lowestValPrintAddress = CONTEXT->program->size();
        }
    break;

  case 155:
#line 1697 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Invalid condition expression "
                        "in 'case()' operator");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 156:
#line 1706 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (7)]).prgsize,
                    CONTEXT->program->end()); //discard program
            (yyval).prgsize = (yyvsp[(1) - (7)]).prgsize; //start of expr prog
            (yyval).val.setString("undefined");
            CODE_VAL(VAL, (yyval).val); //fake value
        }
    break;

  case 157:
#line 1714 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Invalid 'case()' operator arguments");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 158:
#line 1722 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (5)]).prgsize,
                    CONTEXT->program->end()); //discard program
            (yyval).prgsize = (yyvsp[(1) - (5)]).prgsize; //start of expr prog
            (yyval).val.setString("undefined");
            CODE_VAL(VAL, (yyval).val); //fake value
        }
    break;

  case 159:
#line 1734 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
            CODE(JMPIFNOT); //if not true, jump to the next case
        }
    break;

  case 160:
#line 1739 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //save actual addr
        }
    break;

  case 161:
#line 1743 "tengsyntax.yy"
    {
            // propagate end-jump info
            (yyval).addr = (yyvsp[(6) - (6)]).addr;
            // calculate jump offset
            // add +1 for end-jump if some other case option was generated
            (*CONTEXT->program)[(yyvsp[(3) - (6)]).prgsize].value.integerValue =
                    (yyvsp[(5) - (6)]).prgsize - (yyvsp[(3) - (6)]).prgsize - 1
                    + ((yyvsp[(5) - (6)]).prgsize != CONTEXT->program->size());
        }
    break;

  case 162:
#line 1753 "tengsyntax.yy"
    {
            // propagate end-jump info
            (yyval).addr.erase((yyval).addr.begin(), (yyval).addr.end()); //no end-jumps
        }
    break;

  case 163:
#line 1762 "tengsyntax.yy"
    {
            // insert end-jump
            (yyval).prgsize = CONTEXT->program->size(); //save end-jump addr
            CODE(JMP); //previous was true, skip else section
        }
    break;

  case 164:
#line 1768 "tengsyntax.yy"
    {
            (yyval).addr = (yyvsp[(3) - (3)]).addr; //propagate end-jump info
            (yyval).addr.push_back((yyvsp[(2) - (3)]).prgsize);
        }
    break;

  case 165:
#line 1773 "tengsyntax.yy"
    {
            // default value, for case the default value is not supplied
            (yyval).addr.erase((yyval).addr.begin(), (yyval).addr.end()); //clear residuals
            (yyval).addr.push_back(CONTEXT->program->size()); //save end-jump addr
            CODE(JMP); //previous was true, skip else section
            CODE(VAL); //empty value
        }
    break;

  case 166:
#line 1789 "tengsyntax.yy"
    {
            // ordinal literal (int, real or string)
            (yyval).val = (yyvsp[(1) - (1)]).val;
        }
    break;

  case 167:
#line 1794 "tengsyntax.yy"
    {
            // + integer
            (yyval).val = (yyvsp[(2) - (2)]).val;
        }
    break;

  case 168:
#line 1799 "tengsyntax.yy"
    {
            // + real
            (yyval).val = (yyvsp[(2) - (2)]).val;
        }
    break;

  case 169:
#line 1804 "tengsyntax.yy"
    {
            // - integer
            (yyval).val = -(yyvsp[(2) - (2)]).val;
        }
    break;

  case 170:
#line 1809 "tengsyntax.yy"
    {
            // - real
            (yyval).val = -(yyvsp[(2) - (2)]).val;
        }
    break;

  case 171:
#line 1817 "tengsyntax.yy"
    {
            // generate code
            (yyval).val = ParserValue_t();
            (yyval).val.integerValue = 0;
            CODE_VAL(STACK, (yyval).val); //compare to stack top
            CODE_VAL(VAL, (yyvsp[(1) - (1)]).val);
            if ((yyvsp[(1) - (1)]).val.type == ParserValue_t::TYPE_STRING)
                CODE(STREQ); //compare as strings
            else
                CODE(NUMEQ); //compare as numbers
        }
    break;

  case 172:
#line 1829 "tengsyntax.yy"
    {
            // join two case values with OR
            (yyval).prgsize = CONTEXT->program->size(); //save actual prog size
            CODE(OR); //generate infix code
            // generate code
            (yyval).val = ParserValue_t();
            (yyval).val.integerValue = 0;
            CODE_VAL(STACK, (yyval).val); //compare to stack top
            CODE_VAL(VAL, (yyvsp[(1) - (3)]).val);
            if ((yyvsp[(1) - (3)]).val.type == ParserValue_t::TYPE_STRING)
                CODE(STREQ); //compare as strings
            else
                CODE(NUMEQ); //compare as numbers
            // calculate OR-jump offset
            (*CONTEXT->program)[(yyval).prgsize].value.integerValue =
                    CONTEXT->program->size() - (yyval).prgsize - 1;
        }
    break;

  case 173:
#line 1851 "tengsyntax.yy"
    {
            // following code cannot be optimized
            (yyval).prgsize = CONTEXT->program->size(); //start of expr prog
            // clear val and copy variable identifier
            (yyval).val = ParserValue_t(); //clear
            (yyval).id = (yyvsp[(3) - (4)]).id;
            (yyval).val.stringValue = (yyvsp[(3) - (4)]).val.stringValue;
            if ((yyval).id.empty()) {
                // bad identifier -- code fake value
                ERR(ERROR, (yyvsp[(3) - (4)]).pos, "Invalid identifier "
                        "in 'defined()' operator");
                (yyval).val.setString("undefined");
                CODE_VAL(VAL, (yyval).val); //fake value
            } else {
                bool mustBeOpen = false;
                // check for automatic variable
                if ((yyval).id.back() == "_count") {
                    // remove automatic variable name
                    (yyval).id.pop_back();
                    // rebuild identifier
                    buildIdentifier((yyval));
                } else if ((yyval).id.back() == "_number") {
                    // remove automatic variable name
                    (yyval).id.pop_back();
                    // rebuild identifier
                    buildIdentifier((yyval));

                    // this fragment must be open!
                    mustBeOpen = true;
                }

                // resolve existence
                Identifier_t id;
                ParserContext_t::ExistResolution_t er
                    = CONTEXT->exists((yyvsp[(3) - (4)]).pos, (yyval).id, (yyval).val.stringValue, id, mustBeOpen);

                // generate code
                switch (er) {
                case ParserContext_t::ER_FOUND:
                case ParserContext_t::ER_RUNTIME:
                    // object may be defined
                    CODE_VAL(DEFINED, (yyval).val);
                    CONTEXT->program->back().identifier = id;
                    break;

                case ParserContext_t::ER_NOT_FOUND:
                    // object cannot be present => always false
                    (yyval).val.setInteger(false);
                    CODE_VAL(VAL, (yyval).val);
                    break;
                }
            }
        }
    break;

  case 174:
#line 1907 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                if (yychar == LEX_VAR)
                    ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Variable identifier must not "
                            "start with '$' here");
                ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Invalid identifier "
                        "in 'defined()' operator");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 175:
#line 1919 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //start of expr prog
            (yyval).val.setInteger(0);
            CODE_VAL(VAL, (yyval).val); //fake value
        }
    break;

  case 176:
#line 1928 "tengsyntax.yy"
    {
            // following code cannot be optimized
            (yyval).prgsize = CONTEXT->program->size(); //start of expr prog
            // clear val and copy variable identifier
            (yyval).val = ParserValue_t(); //clear
            (yyval).id = (yyvsp[(3) - (4)]).id;
            (yyval).val.stringValue = (yyvsp[(3) - (4)]).val.stringValue;
            if ((yyval).id.empty()) {
                // bad identifier -- code fake value
                ERR(ERROR, (yyvsp[(3) - (4)]).pos, "Invalid identifier "
                        "in 'exist()' operator");
                (yyval).val.setString("undefined");
                CODE_VAL(VAL, (yyval).val); //fake value
            } else {
                bool mustBeOpen = false;
                // check for automatic variable
                if ((yyval).id.back() == "_count") {
                    // remove automatic variable name
                    (yyval).id.pop_back();
                    // rebuild identifier
                    buildIdentifier((yyval));
                } else if ((yyval).id.back() == "_number") {
                    // remove automatic variable name
                    (yyval).id.pop_back();
                    // rebuild identifier
                    buildIdentifier((yyval));

                    // this fragment must be open!
                    mustBeOpen = true;
                }

                // resolve existence
                Identifier_t id;
                ParserContext_t::ExistResolution_t er
                    = CONTEXT->exists((yyvsp[(3) - (4)]).pos, (yyval).id, (yyval).val.stringValue,
                                      id, mustBeOpen);

                // generate code
                switch (er) {
                case ParserContext_t::ER_FOUND:
                    // object found in template => always true
                    (yyval).val.setInteger(true);
                    CODE_VAL(VAL, (yyval).val);

                    break;
                case ParserContext_t::ER_RUNTIME:
                    // object may be present in data => resolution postponed
                    // to runtime
                    CODE_VAL(EXIST, (yyval).val);
                    CONTEXT->program->back().identifier = id;
                    break;

                case ParserContext_t::ER_NOT_FOUND:
                    // object cannot be present in data => always false
                    (yyval).val.setInteger(false);
                    CODE_VAL(VAL, (yyval).val);
                    break;
                }
            }
        }
    break;

  case 177:
#line 1991 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                if (yychar == LEX_VAR)
                    ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Variable identifier must not "
                            "start with '$' here");
                ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Invalid identifier "
                        "in 'exist()' operator");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 178:
#line 2003 "tengsyntax.yy"
    {
            (yyval).prgsize = CONTEXT->program->size(); //start of expr prog
            (yyval).val.setInteger(0);
            CODE_VAL(VAL, (yyval).val); //fake value
        }
    break;

  case 179:
#line 2013 "tengsyntax.yy"
    {
            // call special code generation for functions
            tengCode_generateFunctionCall(CONTEXT,
                    (yyvsp[(1) - (4)]).val.stringValue, //function name
                    (yyvsp[(3) - (4)]).val.integerValue); //number of args
            (yyval).prgsize = (yyvsp[(2) - (4)]).prgsize; //start of expr prog
            tengCode_optimizeExpression(CONTEXT, (yyval).prgsize); //optimize
        }
    break;

  case 180:
#line 2024 "tengsyntax.yy"
    {
            if (tengSyntax_lastErrorMessage.length() > 0) {
                printUnexpectedElement(CONTEXT, yychar, yylval);
                ERR(ERROR, (yyvsp[(1) - (3)]).pos, "Invalid function '"
                        + (yyvsp[(1) - (3)]).val.stringValue + "()' argument(s)");
            }
            tengSyntax_lastErrorMessage.erase(); //clear error
        }
    break;

  case 181:
#line 2033 "tengsyntax.yy"
    {
            CONTEXT->program->erase(CONTEXT->program->begin() + (yyvsp[(1) - (5)]).prgsize,
                    CONTEXT->program->end()); //discard program
            (yyval).prgsize = (yyvsp[(1) - (5)]).prgsize; //start of expr prog
            (yyval).val.setString("undefined");
            CODE_VAL(VAL, (yyval).val); //fake value
        }
    break;

  case 182:
#line 2045 "tengsyntax.yy"
    {
            (yyval).val.integerValue = (yyvsp[(3) - (3)]).val.integerValue + 1; //more than 1 args
        }
    break;

  case 183:
#line 2049 "tengsyntax.yy"
    {
            (yyval).val.integerValue = 1; //single argument
        }
    break;

  case 184:
#line 2053 "tengsyntax.yy"
    {
            (yyval).val.integerValue = 0; //no args
        }
    break;


/* Line 1267 of yacc.c.  */
#line 4149 "tengsyntax.cc"
      default: break;
    }
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);

  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);

  *++yyvsp = yyval;


  /* Now `shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTOKENS];

  goto yynewstate;


/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;
#if ! YYERROR_VERBOSE
      yyerror (YY_("syntax error"));
#else
      {
	YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
	if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
	  {
	    YYSIZE_T yyalloc = 2 * yysize;
	    if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
	      yyalloc = YYSTACK_ALLOC_MAXIMUM;
	    if (yymsg != yymsgbuf)
	      YYSTACK_FREE (yymsg);
	    yymsg = (char *) YYSTACK_ALLOC (yyalloc);
	    if (yymsg)
	      yymsg_alloc = yyalloc;
	    else
	      {
		yymsg = yymsgbuf;
		yymsg_alloc = sizeof yymsgbuf;
	      }
	  }

	if (0 < yysize && yysize <= yymsg_alloc)
	  {
	    (void) yysyntax_error (yymsg, yystate, yychar);
	    yyerror (yymsg);
	  }
	else
	  {
	    yyerror (YY_("syntax error"));
	    if (yysize != 0)
	      goto yyexhaustedlab;
	  }
      }
#endif
    }



  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse look-ahead token after an
	 error, discard it.  */

      if (yychar <= YYEOF)
	{
	  /* Return failure if at end of input.  */
	  if (yychar == YYEOF)
	    YYABORT;
	}
      else
	{
	  yydestruct ("Error: discarding",
		      yytoken, &yylval);
	  yychar = YYEMPTY;
	}
    }

  /* Else will try to reuse look-ahead token after shifting the error
     token.  */
  goto yyerrlab1;


/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR.  |
`---------------------------------------------------*/
yyerrorlab:

  /* Pacify compilers like GCC when the user code never invokes
     YYERROR and the label yyerrorlab therefore never appears in user
     code.  */
  if (/*CONSTCOND*/ 0)
     goto yyerrorlab;

  /* Do not reclaim the symbols of the rule which action triggered
     this YYERROR.  */
  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);
  yystate = *yyssp;
  goto yyerrlab1;


/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
`-------------------------------------------------------------*/
yyerrlab1:
  yyerrstatus = 3;	/* Each real token shifted decrements this.  */

  for (;;)
    {
      yyn = yypact[yystate];
      if (yyn != YYPACT_NINF)
	{
	  yyn += YYTERROR;
	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
	    {
	      yyn = yytable[yyn];
	      if (0 < yyn)
		break;
	    }
	}

      /* Pop the current state because it cannot handle the error token.  */
      if (yyssp == yyss)
	YYABORT;


      yydestruct ("Error: popping",
		  yystos[yystate], yyvsp);
      YYPOPSTACK (1);
      yystate = *yyssp;
      YY_STACK_PRINT (yyss, yyssp);
    }

  if (yyn == YYFINAL)
    YYACCEPT;

  *++yyvsp = yylval;


  /* Shift the error token.  */
  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);

  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturn;

/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturn;

#ifndef yyoverflow
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here.  |
`-------------------------------------------------*/
yyexhaustedlab:
  yyerror (YY_("memory exhausted"));
  yyresult = 2;
  /* Fall through.  */
#endif

yyreturn:
  if (yychar != YYEOF && yychar != YYEMPTY)
     yydestruct ("Cleanup: discarding lookahead",
		 yytoken, &yylval);
  /* Do not reclaim the symbols of the rule which action triggered
     this YYABORT or YYACCEPT.  */
  YYPOPSTACK (yylen);
  YY_STACK_PRINT (yyss, yyssp);
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
		  yystos[*yyssp], yyvsp);
      YYPOPSTACK (1);
    }
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif
#if YYERROR_VERBOSE
  if (yymsg != yymsgbuf)
    YYSTACK_FREE (yymsg);
#endif
  /* Make sure YYID is used.  */
  return YYID (yyresult);
}


#line 2060 "tengsyntax.yy"




/** Lexical analyzer.
  * Calls preprocessor (lex level #1) and lexical analyzer
  * (lex level #2) for some level 1 tokens.
  * @return 0=EOF, >0=element identificator.
  * @param leftValue Pointer to the token's left-value.
  * @param context Pointer to the parser's control structure. */
static int yylex(YYSTYPE *leftValue, void *context)
{
    // positions
    static Error_t::Position_t lex1Pos; //start pos of current lex1 element
    static Error_t::Position_t lex2Pos; //actual position in lex2 stream

    // forever loop
    for ( ; ; ) {

        // if lex2 is currently in use
        if (CONTEXT->lex2) {

            // get next L2 token (>0=tok, 0=eof, -1=err)
            ParserValue_t val;
            Error_t::Position_t pos = lex2Pos;
            int tok = tengLex2_getElement(val, lex2Pos,
                    CONTEXT->program->getErrors());

            if (tok > 0) {
                leftValue->val = val;
                leftValue->pos = pos; //elements position
                CONTEXT->position = pos; //actual position in input stream
                leftValue->prgsize = CONTEXT->program->size();
                return tok; //token
            } else if (tok < 0) {
                ERR(ERROR, pos, "Invalid lexical element");
                continue; //ignore bad element
            }
            // that was last token
            tengLex2_finish();
            CONTEXT->lex2 = 0;
        }

        // test if lex1 stack is empty
        if (CONTEXT->lex1.empty()) {
            leftValue->pos = lex1Pos; //last known position
            CONTEXT->position = lex1Pos; //last known position in input stream
            leftValue->prgsize = CONTEXT->program->size();
            return 0; //EOF
        }
        // remember lex1 position
        lex1Pos = CONTEXT->lex1.top()->getPosition();
        // get next L1 token
        Lex1_t::Token_t tok = CONTEXT->lex1.top()->getElement();
        if (tok.type == Lex1_t::TYPE_TENG
                || tok.type == Lex1_t::TYPE_EXPR
                || tok.type == Lex1_t::TYPE_DICT) {

            // use lex2
            tengLex2_init(tok.value);
            lex2Pos = lex1Pos; //set starting lex2 pos
            CONTEXT->lex2 = 1;
            continue; //read first lex2-element

        } else if (tok.type == Lex1_t::TYPE_TEXT) {

            // plain text
            leftValue->val.setString(tok.value);
            leftValue->pos = lex1Pos; //element's position
            CONTEXT->position = lex1Pos; //actual position in input stream
            leftValue->prgsize = CONTEXT->program->size();
            return LEX_TEXT;

        } else if (tok.type == Lex1_t::TYPE_ERROR) {

            // error
            ERR(ERROR, lex1Pos, tok.value.c_str());
            continue; //ignore bad element
        }

        // EOF from current lex, remove it from stack and try again
        delete CONTEXT->lex1.top();
        CONTEXT->lex1.pop();
        CONTEXT->sourceIndex.pop();

    } //foreverloop
}


/** Error handling function.
  * Function is unusable, because it does not know parser context :-((
  * @return 0=ok.
  * @param msg Error message to show. */
static int yyerror(const char *msg)
{
#if YYDEBUG
    // if debug enabled
    if (yydebug) {
        fprintf(stderr, "\n*** %s ***\n", msg);
    }
#endif
    // use global variable :-((
    tengSyntax_lastErrorMessage = msg;
    return 0;
}


// if enabled debug mode
#if YYDEBUG
/** Print tokens value into file stream.
  * Just for debug purposes.
  * @param fp File to print to.
  * @param element Lexical element number.
  * @param leftValue Token's left-value to print. */
static void yyprint(FILE *fp, int element, const YYSTYPE &leftValue)
{
    fprintf(fp, " '%s', %ld, %f; addr=%d",
            leftValue.val.stringValue.c_str(),
            leftValue.val.integerValue,
            leftValue.val.realValue,
            leftValue.prgsize);
}
#endif

/** Translates token name into teng-syntax-like name
  * @return teng-syntax-like name if token is known
  * @param token Token name. */

static std::string directive(const std::string &token) {
    string directive;
    if (token == "LEX_ENDFORMAT") {
        directive = "<?teng endformat?> directive";
    } else if (token == "LEX_ENDFRAGMENT") {
        directive = "<?teng endfrag?> directive";
    } else if (token == "LEX_ENDIF") {
        directive = "<?teng endif?> directive";
    } else if (token == "LEX_ENDCTYPE") {
        directive = "<?teng endctype?> directive";
    } else {
        directive = token + " token";
    }
    return directive;
}

/** Print info about unexpected element.
  * @param context Actual parser context.
  * @param elem Look-ahead lexical element.
  * @param val Look-ahead element's semantic value. */
static void printUnexpectedElement(ParserContext_t *context,
                                   int element, const YYSTYPE &leftValue)
{
    string msg;
    switch (element) {

        // plain text
        case LEX_TEXT:
            msg = "template's plain text"; break;

        // teng directives
        case LEX_DEBUG:
            msg = "directive '<?teng debug'"; break;
        case LEX_BYTECODE:
            msg = "directive '<?teng bytecode'"; break;
        case LEX_INCLUDE:
            msg = "directive '<?teng include'"; break;
        case LEX_FORMAT:
            msg = "directive '<?teng format'"; break;
        case LEX_ENDFORMAT:
            msg = "directive '<?teng endformat'"; break;
        case LEX_FRAGMENT:
            msg = "directive '<?teng frag'"; break;
        case LEX_ENDFRAGMENT:
            msg = "directive '<?teng endfrag'"; break;
        case LEX_IF:
            msg = "directive '<?teng if'"; break;
        case LEX_ELSEIF:
            msg = "directive '<?teng elseif'"; break;
        case LEX_ELSE:
            msg = "directive '<?teng else'"; break;
        case LEX_ENDIF:
            msg = "directive '<?teng endif'"; break;
        case LEX_SET:
            msg = "directive '<?teng set'"; break;
        case LEX_EXPR:
            msg = "directive '<?teng expr'"; break;
        case LEX_TENG:
            msg = "directive '<?teng'"; break;
        case LEX_END:
            msg = "directive end '?>'"; break;
        case LEX_SHORT_EXPR:
            msg = "directive '${'"; break;
        case LEX_SHORT_DICT:
            msg = "directive '#{'"; break;
        case LEX_SHORT_END:
            msg = "directive end '}'"; break;
        case LEX_CTYPE:
            msg = "directive '<?teng ctype'"; break;
        case LEX_ENDCTYPE:
            msg = "directive '<?teng endctype'"; break;
        case LEX_REPEATFRAG:
            msg = "directive '<?teng repeat'"; break;

        // assignment
        case LEX_ASSIGN:
            msg = "character '='"; break;
        case LEX_COMMA:
            msg = "character ','"; break;

        // conditional expression
        case LEX_COND_EXPR:
            msg = "operator '?'"; break;
        case LEX_COLON:
            msg = "character ':'"; break;

        // comparison operators
        case LEX_EQ:
            msg = "operator '=='"; break;
        case LEX_NE:
            msg = "operator '!='"; break;
        case LEX_STR_EQ:
            msg = "operator '=~'"; break;
        case LEX_STR_NE:
            msg = "operator '!~'"; break;
        case LEX_GE:
            msg = "operator '>='"; break;
        case LEX_LE:
            msg = "operator '<='"; break;
        case LEX_GT:
            msg = "operator '>'"; break;
        case LEX_LT:
            msg = "operator '<'"; break;

        // logic operators
        case LEX_OR:
            msg = "operator '||'"; break;
        case LEX_AND:
            msg = "operator '&&'"; break;

        // bitwise operators
        case LEX_BITOR:
            msg = "operator '|'"; break;
        case LEX_BITXOR:
            msg = "operator '^'"; break;
        case LEX_BITAND:
            msg = "operator '&'"; break;

        // expressions
        case LEX_ADD:
            msg = "operator '+'"; break;
        case LEX_SUB:
            msg = "operator '-'"; break;
        case LEX_CONCAT:
            msg = "operator '++'"; break;
        case LEX_MUL:
            msg = "operator '*'"; break;
        case LEX_DIV:
            msg = "operator '/'"; break;
        case LEX_MOD:
            msg = "operator '%'"; break;
        case LEX_REPEAT:
            msg = "operator '**'"; break;
        case LEX_NOT:
            msg = "operator '!'"; break;
        case LEX_BITNOT:
            msg = "operator '~'"; break;
        case LEX_UNARY: //LEX_UNARY is fake terminal
            msg = "fake lexical element used just for modifying "
                    "precedence of the unary operators. Huh?!?"; break;

        // other keywords/operators
        case LEX_CASE:
            msg = "operator 'case'"; break;
        case LEX_DEFINED:
            msg = "operator 'defined'"; break;
        case LEX_EXIST:
            msg = "operator 'exist'"; break;

        // parentheses
        case LEX_L_PAREN:
            msg = "character '('"; break;
        case LEX_R_PAREN:
            msg = "character ')'"; break;

        // identifiers and literals
        case LEX_VAR:
            msg = "character '$'"; break;
        case LEX_DICT:
            msg = "character '#'"; break;
        case LEX_DICT_INDIRECT:
            msg = "character '@'"; break;

        case LEX_SELECTOR:
            msg = "character '.'"; break;
        case LEX_IDENT:
            msg = "identifier '" + leftValue.val.stringValue + "'"; break;
        case LEX_STRING:
            msg = "string literal '" + leftValue.val.stringValue + "'"; break;
        case LEX_INT:
            msg = "integer literal '" + leftValue.val.stringValue + "'"; break;
        case LEX_REAL:
            msg = "real number literal '"
                    + leftValue.val.stringValue + "'"; break;

        // end of file
        case 0:
            msg = "end of input file while looking for " +
                directive(tengSyntax_lastErrorMessage.substr
                          (tengSyntax_lastErrorMessage.rfind(' ') + 1));
            break;

        default:
            msg = "unknown lexical element. Huh?!?"; break;
    }
    // log error
    ERR(ERROR, leftValue.pos, "Unexpected " + msg);
}

} // namespace Teng

